Last active
August 29, 2015 13:57
-
-
Save escalant3/9783136 to your computer and use it in GitHub Desktop.
Angular idiom to add extra methods to all the $scopes
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.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