尝试向我的收藏中添加内容时出现以下错误:
Exception while invoking method 'submit' Error: key $$hashKey must not start with '$'
每餐对象:
$scope.meal = {
items:[],
createdBy:null
};
这是我的 Controller 内的提交函数:
$scope.submit = function() {
var currentUserId = Meteor.userId();
if(currentUserId!=null) {
if($scope.checkValidity()==false) {
alert("Need to fill out valid calories and/or items!");
}
else {
$scope.meal.createdBy = currentUserId;
Meteor.call("submit", $scope.meal);
alert("has just been submitted");
}
}
else {
alert("You must sign in first!");
}
}
我已经多次检查了我的提交函数,但我似乎找不到错误。我也在谷歌上查看过这个错误,它似乎有点超出我的理解范围,特别是因为我仍然是一个 Angular 初学者。与此同时,我将尝试寻找更多信息。
找到一些信息:https://github.com/Urigo/angular-meteor/issues/299
好像他们从评论中修复了它?然而同样的问题又出现了..检查一下。
最佳答案
要将对象添加到餐食中,请尝试使用:
$scope.meal.items.push(angular.copy($scope.newItem));
当你打电话时
Meteor.call("submit", angular.copy($scope.meal));
这是因为 Angular 使用引用来跟踪对象
关于angularjs - 错误: key $$hashKey must not start with '$' (AngularJS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32173465/