angularjs - angular flash message -
angularjs - angular flash message -
i trying utilize angular api calls server, results server , display results using flash messages...
i using next illustration accomplish flash message output. http://fdietz.github.io/recipes-with-angular-js/common-user-interface-patterns/displaying-a-flash-notice-failure-message.html
my question illustration requires page alter state flash messages can show on page. app has same-page interactions , i'd flash messages show after gets response server though there's no statechange.
also application single page application , don't intent flash messages using page reload.
does know how can accomplish this? or possible? thanks.
<section data-ng-controller="flashcontroller"> <div class="success" ng-show="flash.getmessage()"> <p>{{flash.getmessage()}}</p> </div> </section> <section data-ng-controller="somecontroller"> <button ng-click='somefunction()'></button> </section>
the flash service:
angular.module('mean.system').factory("flash", function($rootscope) { var messagequeue = []; var message = ""; $rootscope.$on("$statechangesuccess", function() { message = messagequeue.shift() || ""; }); homecoming { setmessage: function(message) { messagequeue.push(message); }, getmessage: function() { homecoming message; } }; });
controller:
app.controller("somecontroller", function($scope, $location, flash) { $scope.somefunction = function(message) { flash.setmessage(message); $location.path("/"); <--- when path changes flash message show } });
and jsfiddle in link provided above.
angularjs angular-ui-router
Comments
Post a Comment