1

My project is base on ionic framework, and I am using ngResource in project. Now my requirement is that I want to pass the url dynamically to that ngResource function. For this I create one wrapper for this. And its working properly with get, put, getone method but I have an issue while submitting data to the server and I got this error .$save is not a function. Check this code for more detail.

Wrapper

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;
        }
    }

})

Use in Code :

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

for more detail please refer this link

Community
  • 1
  • 1
RahulSalvikar
  • 658
  • 1
  • 10
  • 31
  • 2
    most people will not download a .git repository in order to troubleshoot an issue of this nature. Also, you didn't include the line of code that is causing this error in your question. – Claies Jul 30 '15 at 13:50
  • 1
    Paste a code of when the error occurs - that is how you are using the service and which method are you calling and how you are calling it. No - providing the Github URL does not work. – callmekatootie Jul 30 '15 at 13:50
  • I already try this thing but its not working. like this-> save: {method: 'POST'}. That's why I post git hub repository URL. – RahulSalvikar Jul 30 '15 at 17:21
  • I update the question please refer this... – RahulSalvikar Jul 30 '15 at 17:30
  • 1. why do you define a method for `$resource` which already exists with [same options](https://docs.angularjs.org/api/ngResource/service/$resource) (see section Returns)? 2. after defining `save` method why would call it like `.$save()`? the method name is `.save()`... – Kirill Slatin Jul 30 '15 at 18:07

0 Answers0