1

我正在尝试向我的 ngResource 工厂方法添加一个原型函数,如下所示:

 .factory('Magazine', function ($resource) {

var Magazine = $resource('http://localhost/dooleystand/ci/api/magazine/:magId', {
  loginID : organEntity,
  password : organCommpassword,
  magId : "@magId"
});

Magazine.prototype.getLastAdded = function() {
  return this.get({magId:"lastAdded"});
};

return Magazine;

})

然后我尝试从控制器中的函数调用这个工厂方法:

Magazine.save(magazine, function() {

    var newMagazine = Magazine.getLastAdded;

    var tempMagazine = {
            issue_number : newMagazine.issue_number,
        magazine_name : newMagazine.magazine_name
    };
    $scope.magazines.push(tempMagazine);
    });

似乎我的浏览器根本没有生成新请求。有什么方法可以真正做到这一点,还是我需要一个单独的工厂方法?

4

1 回答 1

1

像这样扩展资源操作怎么样?

.factory('Magazine', function ($resource) {
    return $resource('http://localhost/dooleystand/ci/api/magazine/:magId', {
        loginID: organEntity,
        password: organCommpassword,
        magId: "@magId"
    }, {
        getLastAdded: { method: 'GET', params: { magId: 'lastAdded' } }
    });
}
于 2013-10-16T02:14:42.870 回答