AngularJS: what is the execution order of $watch? -


i have watch function:

scope.$watch('target', function(){    scope.hasunsavedchanges = true; }, true); 

then change value:

functiion change(target){    scope.hasunsavedchanges = false;    scope.target.xxx = '';    console.log('scope.hasunsavedchanges = ' + scope.hasunsavedchanges);  } 

it outputs false. when watch function executes? , how run code after scope.hasunsavedchanges becomes true in above code?

$watch functions executes after every time $scope.$digests() function called.

and if want execute code after variable hasunsavedchanges become true. wouldn't make more sense make function instead , execute code there like:

scope.setunsavedchanges = function(){     scope.hasunsavedchanges = true;    //the rest of code goes here }  scope.$watch('target', function(){    scope.setunsavedchanges(); }, true); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -