这是一个问卷应用程序。我有一个指令,它是一系列用于对问题做出选择的按钮。每个问题都是一个带有选择分数的 JSON 对象。我希望突出显示与所选分数相对应的按钮,并单击未选择的按钮来更改分数。
我还没有在控制器中编写 updateQuestion(),因为我需要先弄清楚如何让他们以 Angular 的方式交谈。
按钮的指令
giftsAppsModule.directive('questionChoice',function(){
return {
restrict: 'E',
replace: true,
template :'<div class="btn-group btn-group-vertical">' +
'<button class="btn btn-block" ng-click="updateQuestion(5)">Love It</button>' +
'<button class="btn btn-block" ng-click="updateQuestion(3)">Enjoy It</button>'+
'<button class="btn btn-block" ng-click="updateQuestion(2)">Maybe</button>' +
'<button class="btn btn-block" ng-click="updateQuestion(1)">Probably not</button>'+
'<button class="btn btn-block" ng-click="updateQuestion(0)">No way!</button></div>'
}
问题
questionlist= [
{"index": 1, "question": "Rejoice in God's provision even when the checkbook is in the red.", "gift": "FTH", "score": null},
{"index": 2, "question": "Clean the kitchen once a week.", "gift": "SVC", "score": null},
{"index": 3, "question": "Build sets for a drama.", "gift": "CFT", "score": null},
{"index": 4, "question": "Search the Bible to check the validity of a sermon or Bible lesson.", "gift": "DSC", "score": null}]}
相关的html
<div ng-repeat="question in questionlist">
<div class="row-fluid">
<div class="span6">
<p>{{question.index}}. {{question.question}}</p>
</div>
<div class="span6">
<question-choice></question-choice>
</div>
</div>
</div>