我正在嘗試遍歷questions
的數組。但我需要在每個問題上附上單選按鈕答案。 在這種情況下,我需要爲每個答案添加不同的ng-model
。 我試過下面的代碼,但它沒有奏效。
這是使用ng-repeat
的$index
的正確方法嗎?
<li class="fields" ng-repeat="question in questions">
<p>question:{{question.title}}</p>
<div class="radio-buttons">
<input type="radio" id="radio01" value="0" ng-model="answer[$index]" checked="checked"/>
<label for="radio01"><span></span>Yes</label>
<input type="radio" id="radio02" value="1" ng-model="answer[$index]"/>
<label for="radio02"><span></span>No</label>
</div>
</li>
什麼不行?這看起來應該把所有答案(0/1)放在一個'answer'數組中。或者,也許你想'ng-model =「question.answer」'? – devqon