Last active
August 29, 2015 14:08
-
-
Save pulpfree/f060545d9a9bd8a876d0 to your computer and use it in GitHub Desktop.
Delay angularjs $watch response
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
| // 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