Created
July 23, 2013 15:56
-
-
Save EpokK/6063560 to your computer and use it in GitHub Desktop.
Unwatch an expression: Sometimes you want to watch an expression only a few times, and then forget it. The $watch function returns a callback just for that. You just have to execute it back to destruct the watcher.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var watcher = $scope.$watch('data.counter', function(newValue, oldValue) { | |
iElement.css('width', 50 * newValue + 'px'); | |
if (newValue >= 10) { | |
// when data.counter reaches 10, destruct the watcher. | |
watcher(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment