I want to update my json object with PUT method using the update function in angularjs but after using the update method I get the error of :
angular.js:14324 TypeError: menuFactory.getDishes(...).update is not a function
at b.$scope.submitComment (controllers.js:104)
at fn (eval at compile (angular.js:15152), <anonymous>:4:159)
at e (angular.js:26673)
at b.$eval (angular.js:17958)
at b.$apply (angular.js:18058)
at HTMLFormElement.<anonymous> (angular.js:26678)
at bg (angular.js:3613)
at HTMLFormElement.d (angular.js:3601)
This is my service.js code :
.service('menuFactory', ['$resource', 'baseURL', function($resource,baseURL) {
this.getDishes = function(){
return $resource("localhost:3000/"+"dishes/:id",{update:{method:'PUT' }});
};
}])
and this is my controller code :
.controller('DishCommentController', ['$scope', 'menuFactory', function($scope,menuFactory) {
$scope.mycomment= {rating:"5", comment:"", author:""};
$scope.dish.comments.push($scope.mycomment);
menuFactory.getDishes().update({ id:$scope.dish.id }, $scope.dish);
}])
why angular doesn't recognize the update method , I had the same issues with get method , but after updating my angular to 1.6.0 version the problem with get method solved . but now I have the same problem with Update method.
What I am doing wrong here?
I think you might be calling $resource incorrectly.
Documentation and look at the usage:
$resource(url, [paramDefaults], [actions], options);
You were sending in actions as the paramDefault parameters, so just enter an empty literal for that parameter, unless you want to customise it.
Change
$resource("localhost:3000/"+"dishes/:id",{update:{method:'PUT' }});
to
$resource("localhost:3000/"+"dishes/:id",{}, update:{method:'PUT' }});