Skip to content

Instantly share code, notes, and snippets.

@escalant3
Last active August 29, 2015 13:57
Show Gist options
  • Save escalant3/9783136 to your computer and use it in GitHub Desktop.
Save escalant3/9783136 to your computer and use it in GitHub Desktop.
Angular idiom to add extra methods to all the $scopes
angular.module('foo', [])
.config(function($provide) {
$provide.decorator('$rootScope', function ($delegate) {
// Shim needed for browsers I don't care about
var proto = Object.getPrototypeOf($delegate);
proto.$bar = function() {
// Do something
};
return $delegate;
})
})
.controller('MainCtrl', function($scope) {
$scope.$bar();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment