title: AngularJS - creating a service object
body: <p>Instead of posting in Angular mailing list, I think this may be more of javascript question. Hope the SO community can also give faster response.</p>
  
  <p>I am trying to encapsulate the data in a service and injecting into controller.</p>
  
  <pre><code>angular.module('myApp.services', ['ngResource']).
      factory('Player', function($resource){
          var Player ;
          Player = {
              resource: $resource('/api/Player/:_id', {} )
          };
          return Player
  });
  
  
  function PlayerDetailCtrl(Player, $routeParams, $scope) {
      $scope.resource = Player.resource.get({_id:$routeParams._id});
  }
  PlayerDetailCtrl.$inject = ['Player', '$routeParams', '$scope'];
  </code></pre>
  
  <p>It throws an exception</p>
  
  <pre><code>TypeError: Object #&lt;Object&gt; has no method 'query'
  </code></pre>
  
  <p><code>$scope.resource = Player.Player.resource.get({_id:$routeParams._id});</code> also throws error</p>
  
  <pre><code>TypeError: Object #&lt;Object&gt; has no method 'query'
  </code></pre>
  
  <p>the below works.</p>
  
  <pre><code>angular.module('myApp.services', ['ngResource']).
      factory('Player', function($resource){
          var Player ;
          Player= $resource('/api/Player/:_id', {} )
          return Player
  });
  
  
  function PlayerDetailCtrl(Player, $routeParams, $scope) {
      $scope.resource = Player.Player.get({_id:$routeParams._id});
  }
  PlayerDetailCtrl.$inject = ['Player', '$routeParams', '$scope'];
  </code></pre>
  
  <p>my intention is to add more data and method to <code>Player</code>. So how can I make the first (object form) works!</p>