angularjs - Angular Watch and ng-click sequence of events -
i have code within angular directive, , i'm finding $watch behavior bit confusing. updateselect called in "ng-click":
scope.updateselect = function (type) { scope.selectionctrl.activelist = scope.seedlists[type]; scope.selectionctrl.activelistkey = type; scope.selectionctrl.activeselection = scope.selection[type]; scope.selectionctrl.staged = []; scope.selectionctrl.stageremove = []; if (type !== scope.activetab) { scope.activetab = type; } console.log("update"); }; scope.$watch('selectionctrl.activelist', function(newvalue, oldvalue) { console.log("watch"); }, true);
when click on button (triggering updateselect), , watch console, see "update" , "watch". first thing happens within function selectionctrl.activelist
set, expect see "watch" , "update".
shouldn't watch trigger array has changed?
the function has finish first javascript single threaded.
because function called via ng-click directive, angular run digest cycle. part of digest cycle run through watch list , resolve changes may have occurred since cycle lastly ran.
in illustration give, selectionctrl.activelist changed in updateselect subsequently results in watch callback beingness called.
angularjs
No comments:
Post a Comment