Skip to content

Instantly share code, notes, and snippets.

@pulpfree
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save pulpfree/f060545d9a9bd8a876d0 to your computer and use it in GitHub Desktop.

Select an option

Save pulpfree/f060545d9a9bd8a876d0 to your computer and use it in GitHub Desktop.
Delay angularjs $watch response
// Taken from: http://stackoverflow.com/questions/20397253/implement-a-delay-on-scope-watch
var timeoutPromise;
var delayInMs = 0;
vm.isEdit = false;
$scope.$watch(function () {
return vm.editId;
}, function (currentValue) {
$timeout.cancel(timeoutPromise); //does nothing, if timeout alrdy done
timeoutPromise = $timeout(function() {
vm.isEdit = currentValue;
vm.submitLabel = currentValue ? 'Update Fabric' : 'Save New Fabric';
}, delayInMs);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment