title: Shared methods within angular controllers
body: <p>I understand how one may have shared methods across various controllers. For example <a href="http://fdietz.github.io/recipes-with-angular-js/controllers/sharing-code-between-controllers-using-services.html" rel="nofollow">http://fdietz.github.io/recipes-with-angular-js/controllers/sharing-code-between-controllers-using-services.html</a>. However, I was wondering whether it is possible to share methods without necessarily having to declare them within every controller.</p>
  
  <p>So instead of ...</p>
  
  <pre><code>var app = angular.module("MyApp", []);
  
  app.factory("UserService", function() {
    var users = ["Peter", "Daniel", "Nina"];
  
    return {
      all: function() {
        return users;
      },
      first: function() {
        return users[0];
      }
    };
  });
  
  app.controller("MyCtrl", function($scope, UserService) {
    $scope.users = UserService.all();
  });
  
  app.controller("AnotherCtrl", function($scope, UserService) {
    $scope.firstUser = UserService.first();
  });
  </code></pre>
  
  <p>... would it be possible to do without the statements <code>$scope.users = UserService.all();</code> and <code>$scope.users = UserService.all();</code>, but still have them available from the views? Otherwise, if I have ten different controllers, I would have to repeat the same statements ten times.</p>