Skip the initial call to $ watch

So apologize in advance for the scary title. I really don't know all the right angular terms for these things.

I have code similar to this in scope:

$scope.catName = 'Le cat' //<-- Magic goes here $scope.$watch('catName', function () { //[...] }) 

Now, when angular waits until the next digest (is that the right term?) To evaluate the clock, my original assignment ("Le cat") will call the clock.

I would like this indication to not trigger the clock, but after that it will change.

Is there any way to reset the "dirty state" of catName?

Js fiddle: http://jsfiddle.net/7DNrD/1/

+7
source share
1 answer

Check out this workaround

http://jsfiddle.net/7DNrD/5/

 $scope.catName = 'Le cat' $scope.$watch('catName', function (newValue, oldValue) { if(oldValue === newValue){ return; } //[...] }) 
+16
source

All Articles