Angularjs 角度ng重复(&ng)firebase未更新的ng模型
我正在使用angularfire,我的民意调查应用程序已经到了最后阶段,有人投票,点击提交并更新countor标记,这就是我在问题中所说的。以下是我的数据模型:Angularjs 角度ng重复(&ng)firebase未更新的ng模型,angularjs,firebase,ng-repeat,Angularjs,Firebase,Ng Repeat,我正在使用angularfire,我的民意调查应用程序已经到了最后阶段,有人投票,点击提交并更新countor标记,这就是我在问题中所说的。以下是我的数据模型: "-JOiDEYd8ANSv9jbL5qJ" : { "question" : "Coffee or Tea?", "options" : [ { "mark" : 0, "option" : "Coffee" }, { "mark" : 0, "option" :
"-JOiDEYd8ANSv9jbL5qJ" : {
"question" : "Coffee or Tea?",
"options" : [ {
"mark" : 0,
"option" : "Coffee"
}, {
"mark" : 0,
"option" : "Tea"
} ]
},
"-JOiD7pd0fpY_lvYr74s" : {
"question" : "Bagels or Waffles?",
"options" : [ {
"mark" : 0,
"option" : "Bagels"
}, {
"mark" : 0,
"option" : "Waffles"
} ]
},
以下是我的html,用户在进行投票时看到的内容:
<form role="form" ng-submit="pollSubmit()">
<div class = "form-group" ng-repeat="option in selected.options">
<input type="radio" name = "answer" ng-value="1" ng-model="option.mark" > {{option.option}}
</div>
<div class="form-group">
<input class="btn btn-primary btn-xs pull-left" type="submit" value="Submit Poll">
</div>
</form>
你应该更新一个空对象吗?不,对不起,我仍然不太确定$update如何在ng repeat中使用ng模型。如何获取$update对象中的options.mark?在将其放入pollSubmit函数之前,是否需要先将其设置为$scope.mark变量?
'use strict';
angular.module('controllers', [])
.controller('homeCtrl', ['$scope', '$firebase', function ($scope, $firebase){
$scope.total = null;
var ref = new Firebase('https://resplendent-fire-5367.firebaseio.com/');
$scope.polls = $firebase(ref);
$scope.title = 'Active Polls';
$scope.select = function(poll){
$scope.selected = poll;
};
$scope.pollSubmit = function (){
if(confirm('Submit response?')){
$scope.polls.$update({
})
}else{
return;
}
};
}]);