AngularJS - 成功不是一个功能

时间:2016-05-25 08:02:39

标签: angularjs

有这个工厂:

phonecatServices.factory('Phone', ['$resource',
 function($resource){
    return $resource('phones/:phoneId.json', {}, {
    query: {method:'GET', params:{phoneId:'phones'}, isArray:true}
  });
}]);

我使用此服务但收到success is not a function错误:

    Phone.get({phoneId: $routeParams.phoneId}).$promise.then(
        function(data){
            ici.phone = data;
            ici.mainImageUrl = data.images[0];
        },
        function(reason){
            alert("Phone error: " + reason);
        }
    );

c是我的关闭。

你能帮忙吗?

1 个答案:

答案 0 :(得分:0)

使用.success时,

ngResource无法直接使用。您需要使用$promise.then$promise.success来访问promise中的方法。所以你的更新代码看起来像这样

Phone.get({phoneId: $routeParams.phoneId})
  .$promise
  .then(function(data){
        c.phone = data;
        c.mainImageUrl = data.images[0];
    });
相关问题