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