[英]Issue with $http service in Angular 1.2
I just started using Angular 1.2.0 in my development app, and I noticed that the following function doesn't work anymore, take a look: 我刚开始在我的开发应用程序中使用Angular 1.2.0,我注意到以下功能不再起作用了,看看:
var myItems = angular.model('myItems', []);
myItems.controller('itemsController', function($scope, $http) {
// delete item from the database
$scope.deleteItem = function(id) {
$http.delete('/api/items/' + id)
.success(function(data) {
$scope.items = data;
})
.error(function(data) {
// log error
});
};
});
Then in my view, this is what triggers deleting an item: 然后在我看来,这是触发删除项目的原因:
<input type="checkbox" data-ng-click="deleteItem(item._id)"> {{ item.text }}
I'm very fresh to Angular, so I'm not sure what's exactly going wrong here, and a look at the changelog file for version 1.2 on the Angular repository didn't yield an answer. 我对Angular很新鲜,所以我不确定这里到底出了什么问题,看看Angular存储库1.2版的changelog文件并没有得出答案。 Can somebody with more experience in Angular please explain to me what exactly the problem is here?
可以在Angular有更多经验的人请向我解释这里究竟是什么问题?
Edit : here's the log from the Chrome error console, which is visible as soon as the page is loaded. 编辑 :这是来自Chrome错误控制台的日志,只要加载页面就会显示该日志。 Clicking the checkbox to delete an item does nothing.
单击复选框以删除项目不执行任何操作。
Error: [$parse:isecprv] http://errors.angularjs.org/undefined/$parse/isecprv?p0=deleteItem(item._id)
at Error (<anonymous>)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:6:453
at ha (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:84:103)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:87:372
at Array.forEach (native)
at q (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:7:261)
at rc (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:87:354)
at Jb.readIdent (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:149:31)
at Jb.lex (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:144:199)
at Ya.parse (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:151:12) <input type="checkbox" data-ng-click="deleteItem(item._id)">
Update : It turns out that one of the breaking changes in Angular 1.2.0-rc2 (currently latest stable build) is the introduction of private properties on the scope chain. 更新 :事实证明, Angular 1.2.0-rc2 (目前最新的稳定版本)中的一个重大变化是在作用域链上引入了私有属性。 This potentially breaks a lot of apps that stores data in document-oriented databases such as, in my case
MongoDB
. 这可能会破坏许多在面向文档的数据库中存储数据的应用程序,例如我的
MongoDB
。 If you're someone facing this same issue, you can either go back to version 1.2.0-rc3 (Google CDN here ) for now or wrap your sensitive APIs in a closure/controller as suggested in the changelog. 如果您遇到同样的问题,可以暂时返回1.2.0-rc3版本( 此处为Google CDN),也可以按照更改日志中的建议将敏感API打包到闭包/控制器中。
In error console first link points to the page 在错误控制台中,第一个链接指向该页面
http://docs.angularjs.org/error/$parse:isecprv?p0=deleteItem(item._id) http://docs.angularjs.org/error/$parse:isecprv?p0=deleteItem(item._id)
This page explains that the error is that you use private property in expression. 此页面解释了错误是您在表达式中使用私有属性。
The expression is deleteItem(item._id)
. 表达式是
deleteItem(item._id)
。
_id
- is a private property of item. _id
- 是项目的私有财产。
Try changing the field name ( _id ) . 尝试更改字段名称 ( _id )。 This error is clear from the error console.
错误控制台可以清楚地看到此错误。
From Angular version 1.2 来自Angular 1.2版
Referencing private fields in Angular expressions is disallowed!
不允许在Angular表达式中引用私有字段! Expression: deleteItem(item._id)
表达式:deleteItem(item._id)
Fields with names that begin or end with an underscore are considered private fields. 名称以下划线开头或结尾的字段被视为私有字段。 Angular expressions are not allowed to reference such fields on the scope chain.
不允许Angular表达式引用作用域链上的此类字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.