AngularJS Intercept and extend controller $scope

Viewed 9579

There is a lot of reusable functionality that I have defined in my application that EVERY controller uses with the $scope variable. Instead of me having to create a shared service each time, is there a way to extend the $scope variable so that I can have my extended code available everywhere?

Something like:

//I've tested this out and it doesn't work, but this is what I want to do.
angular.module('App',[]).config(['$scopeProvider',function($scope) {
  $scope.method1 = function() { ... };
  $scope.method2 = function() { ... };
}]);

Then later on:

var HomeCtrl = function($scope) {
  $scope.method1();
};

Is this possible? Or do I need to create a shared service and then have the $scope extend from that for the first line of each controller?

1 Answers
Related