【问题标题】:Error: key $$hashKey must not start with '$' (AngularJS)错误:键 $$hashKey 不能以“$”开头(AngularJS)
【发布时间】:2015-11-17 08:31:19
【问题描述】:

当我遇到以下错误时尝试向我的收藏添加一些东西:

Exception while invoking method 'submit' Error: key $$hashKey must not start with '$'

每餐对象:

$scope.meal = {
  items:[],
  createdBy:null
};

这是我的控制器中的提交函数:

$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

似乎他们从 cmets 修复了它?然而,同样的问题出现了..检查出来。

【问题讨论】:

  • 他们建议的解决方案,即Meteor.call('submit', angular.copy($scope.meal)),能解决问题吗?
  • 天啊..我昨晚试过了,但没有用。但我刚刚意识到我做错了什么..omg 问题就在那里,我只是没有看到它..好吧,我想一双新的眼睛总是有帮助的!太感谢了!在我修复了一些我遇到的语法问题后,工作得很好。

标签: angularjs meteor


【解决方案1】:

要将对象添加到餐点,请尝试使用:

  $scope.meal.items.push(angular.copy($scope.newItem));

当你打电话时

 Meteor.call("submit", angular.copy($scope.meal));

这是因为 Angular 使用引用来跟踪对象

【讨论】:

  • 感谢家人! @埃斯特班
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-28
  • 2013-11-07
  • 2017-02-07
  • 1970-01-01
  • 1970-01-01
  • 2014-03-14
  • 2021-05-24
相关资源
最近更新 更多