Skip to content

Instantly share code, notes, and snippets.

@EpokK
Created July 23, 2013 15:56
Show Gist options
  • Save EpokK/6063560 to your computer and use it in GitHub Desktop.
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.
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