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
Post a Comment