angular。$ save不是一个函数

时间:2015-07-30 13:44:43

标签: angularjs ionic-framework angularjs-ng-resource

我的项目基于离子框架,我在项目中使用ngResource。现在我的要求是我想动态地将url传递给ngResource函数。为此,我为此创建了一个包装器。并且它使用get,put,getone方法正常工作,但是在向服务器提交数据时遇到了问题,我收到此错误。$ save不是函数Check this code for more detail.

包装

angular.module('ClientAPI.services', [])
.factory('ClientAPI', function ($resource) {
    var _passUrl;
    var _passParameters;

    return{
        passUrl:_passUrl,
        passParameters: _passParameters,
        callAPIClient : function(){
            return  $resource( this.passUrl, this.passParameters, {
                'update': {
                    method: 'PUT'
                }
            })
        },
        setURL: function(url){
            this.passUrl = url
        },
        setParameters: function(params){
            this.passParameters = params;
        }
    }

})

在代码中使用:

$scope.movie = new ClientAPI.callAPIClient();
    $scope.addMovie = function () {
        $scope.movie.$save(function () {
            $state.go('app.movies');
        });
    }

有关详细信息,请参阅此link

0 个答案:

没有答案