Reputation: 3441
So apologies in advance for the terrible title. I don't really know all the correct angular terminology for these things.
I have code like this in a scope:
$scope.catName = 'Le cat'
//<-- Magic goes here
$scope.$watch('catName', function () {
//[...]
})
Now since angular waits until the next digest (is that the correct term?) to evaluate the watch, my initial assignment ('Le cat') will trigger the watch.
I would like this assigment to not trigger the watch, but changes after this to do so.
Is there some way to reset the 'dirty state' of catName?
Js-fiddle: http://jsfiddle.net/7DNrD/1/
Upvotes: 7
Views: 2654
Reputation: 4275
Check this workaround
$scope.catName = 'Le cat'
$scope.$watch('catName', function (newValue, oldValue) {
if(oldValue === newValue){
return;
}
//[...]
})
Upvotes: 16