我认为这可能更多的是 javascript 问题,而不是在 Angular 邮件列表中发布。希望 SO 社区也能给予更快的响应。
我正在尝试将数据封装在服务中并注入控制器。
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'];
它抛出一个异常
TypeError: Object #<Object> has no method 'query'
$scope.resource = Player.Player.resource.get({_id:$routeParams._id});
也会抛出错误
TypeError: Object #<Object> has no method 'query'
以下作品。
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'];
我的意图是向Player
. 那么我怎样才能使第一个(对象形式)起作用!