我得到一个$ save()不是Angular中的函数

编程入门 行业动态 更新时间:2024-10-28 10:24:51
本文介绍了我得到一个$ save()不是Angular中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试遵循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中的函数

本文发布于:2023-07-26 11:49:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1216032.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   save   Angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!