$ getRecord不会导致Angular Fire中的$ save方法可用

时间:2015-12-21 20:11:50

标签: javascript angularjs firebase angularfire

我正在使用Firebase和AngularFire来尝试保持我的数据同步。我的代码是:

var questionsRef, ref, ref1;

questionsRef = fbase.child("questions").orderByChild("subject").equalTo("english");

$scope.questions = $firebaseArray(questionsRef);

$scope.questions.$loaded().then(function() {
  if ($stateParams.id) {
    $scope.currentQuestion = $scope.questions.$getRecord($stateParams.id);
    return console.log($scope.currentQuestion);
  } else {
    return $scope.currentQuestion = {
      answers: []
    };
  }
});

$scope.currentQuestion.editedByUserId = (ref = auth.$getAuth()) != null ? (ref1 = ref.auth) != null ? ref1.uid : void 0 : void 0;

$scope.currentQuestion.editedOn = Firebase.ServerValue.TIMESTAMP;

$scope.currentQuestion.$save();

应该将更新保存到currentQuestion(基于HTML中的表单ng-model),而是Error: $scope.currentQuestion.$save is not a function. (In '$scope.currentQuestion.$save()', '$scope.currentQuestion.$save' is undefined)

我做错了什么?

1 个答案:

答案 0 :(得分:0)

唉 - 这太傻了。事实证明我错了。我需要做

$scope.questions.$save($scope.currentQuestion)

由于$save列在questions数组