2016-12-14 10 views
0

我想用在angularjs更新功能来更新我的JSON对象与PUT方法更新方法,但使用的更新方法后出现的问题,我得到的错误:在angularjs

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) 

这是我service.js代码:

.service('menuFactory', ['$resource', 'baseURL', function($resource,baseURL) { 
      this.getDishes = function(){ 
       return $resource("localhost:3000/"+"dishes/:id",{update:{method:'PUT' }}); 

           };  
    }]) 

,这是我的控制器代码:

.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); 
    }]) 

为什么角不RECOG nize更新方法,我有get方法相同的问题,但更新我的角度1.6.0版本后get方法解决问题。但现在我有与Update方法相同的问题。

我在做什么错在这里?

+0

更新我的答案。 – Baconbeastnz

回答

0

我想你可能会错误地调用$资源。

Documentation,并期待在用法:

$resource(url, [paramDefaults], [actions], options); 

您在行动作为paramDefault参数进行发送,所以只需输入一个空的文字为参数,除非你想进行自定义。

变化

$resource("localhost:3000/"+"dishes/:id",{update:{method:'PUT' }}); 

$resource("localhost:3000/"+"dishes/:id",{}, update:{method:'PUT' }}); 
+0

非常感谢,工作!但那个空的物体是做什么的? –

+0

更新的答案反映了这一点。 – Baconbeastnz