Last active
February 28, 2018 19:19
-
-
Save marlun78/28874591822d5aa4216a to your computer and use it in GitHub Desktop.
Angular $rootScope.Scope.$once
This file contains 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
/** | |
* Angular $rootScope.Scope.$once | |
* Copyright (c) 2014 marlun78 | |
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83 | |
*/ | |
$provide.decorator('$rootScope', function ($delegate) { | |
var Scope = $delegate.__proto__.constructor; | |
Scope.prototype.$once = function (name, listener) { | |
var deregister = this.$on(name, function () { | |
deregister(); | |
listener.apply(this, arguments); | |
}); | |
return deregister; | |
}; | |
return $delegate; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment