javascript - Will Angular Scope events (sent via `$broadcast`) go on the event queue? -
i trying $broadcast
event indicate ajax happening, ui disables controls in form. seems these events not go onto event queue , handled.
the code working on depends on behaviour, wondering how dependable this? authoritative link helpful (the doc not mention specific).
edit - after reading comments, might make more sense build queue system dependency injection , callbacks.
app.factory('firstservice', function($rootscope, secondservice){ $rootscope.loading = true .success(function(){ secondservice.ajaxcall(); }); }) .factory('secondservice', function($rootscope){ var vm = this; vm.ajaxcall = function(){ $rootscope.processing = true; //ajax call .complete(function(){ $rootscope.processing = false; $rootscope.loading = false; }) } }) .controller('firstcontroller', function($rootscope){ var vm = this; vm.loading = $rootscope.loading; }) .controller('secondcontroller', function($rootscope){ var vm = this; vm.processing = $rootscope.processing; }); <div ng-controller="firstcontroller first"> <form ng-disabled="first.loading"><form> </div> <div ng-controller="secondcontroller second"> <img ng-show="second.processing" /> </div>
$broadcast
blasts event down scope, makes sense fired , not put event queue. here's visualization:
like muenchdo suggest, might want add scope variable indicate whether controls should enabled/disabled.
add logic controller:
app.module('appctrl', function($rootscope){ var vm = this; vm.loading = $rootscope.loading; });
then add ngdisabled logic html:
<div ng-controller="appctrl app"> <form ng-disabled="app.loading"><form> </div>
then before ajax call, set $rootscope
variable:
app.service($rootscope){ $rootscope.loading = true; //ajax call .complete(function(){ $rootscope.loading = false; }); }
Comments
Post a Comment