Skip to content

Instantly share code, notes, and snippets.

@jarbitlira
Forked from marlun78/$once.js
Last active September 19, 2016 18:56
Show Gist options
  • Save jarbitlira/14efea1d2e98e730f6ab to your computer and use it in GitHub Desktop.
Save jarbitlira/14efea1d2e98e730f6ab to your computer and use it in GitHub Desktop.
Angular $rootScope.Scope.$once
/**
* Angular $rootScope.Scope.$once
* Copyright (c) 2014 marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*/
$provide.decorator('$rootScope', function ($delegate) {
var Scope = Object.create($delegate).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