angularjs - Why does a $rootScope.$watch return a value multiple times? -
i have angular app has controller function watches variable changes in rootscope; is,
angular.module('myapp').controller('mycontroller', function($scope, $rootscope) { $rootscope.$watch('somevar', function() { console.log($rootscope.somevar); }); } for reason though, if change $rootscope.somevar "hello", following console output
> hello > hello > hello why doing this? writing program parses large datafiles, , if 3 fold increase in performance, life lot happier.
if side effect of watch results in variable change, watch gets called again until changes resolved.
so if action results in watch getting triggered (the action changes somevar) results in other actions update somevar, there can cascade (up 10 times before angular says enough?)
Comments
Post a Comment