我正在尝试遵循ProAngular一书的教程来构建一个相对简单的Web应用程序.书中的示例工作正常,但是当我尝试构建自己的应用程序时,我陷入了一个奇怪的错误.这是我的代码的一部分:
I am trying to build a relatively simple web application following tutorials from the book ProAngular. The book examples work fine, but when I try and build my own app, I am getting stuck on a strange error. Here is part of my code:
$scope.dispositionsResource = $resource(dispositionUrl + ":id", { id: "@id" }, { create: {method: "POST"}, save: {method: "PUT"}, delete: {method: "DELETE"} });. .
$scope.updateDisposition = function (disposition) { alert("DISPOSITION: "+disposition.name); disposition.$save(); }创建和删除功能可以正常工作.正在从HTML表单中调用updateDisposition方法,并且正在传递正确的处置值(基于Alert).但是我得到的错误是:
The Create and Delete functions work fine. The updateDisposition method is being called form an HTML form and the correct disposition value is being passed (based on the Alert). But the error I am getting is:
"Error: disposition.$save is not a function"我的示例代码都没有单独定义保存功能,该功能应该是restful服务($ resource)的一部分.不是吗?
None of my example code separately defines a save function, the function should be part of the restful service ($resource). Shouldn't it?
任何朝着正确方向的指针将不胜感激.
Any pointers in the right direction would be greatly appreciated.
泰德
推荐答案我最终还是可以正常工作的.不能完全确定为什么,但是我将保存功能重命名为更新",并将其与PUT功能相关联.
I did end up getting this working. Not totally sure why, but I renamed the Save function to 'Update' and associated it with the PUT functionality.
$scope.dispositionsResource = $resource(dispositionUrl+":id", { id: "@id" }, { 'create': {method: "POST"}, 'update': {method: "PUT"} }); $scope.updateDisposition = function (disposition) { $scope.dispositionsResource.update(disposition); $scope.editedDisposition = null; }调用更新而不是保存工作.似乎在干扰保存"一词的使用.就像我说的那样,不确定是什么. . .然而.对我来说,这些抓头人之一.感谢那些试图提供帮助的人!
calling update rather than save worked. Something seemed to be interfering with using the term 'save'. Like I said, not sure what . . . yet. One of those head-scratchers for me. Thanks to those who tried to assist!
更多推荐
我得到一个$ save()不是Angular中的函数
发布评论