不確定發生了什麼,但看起來像我的表達式沒有得到評估或擴展。在ng-if中包含另一個ng-repeat的角度ng-repeat
<div ng-repeat-start="q in questions">
<h3>{{q.text}}</h3>
<p ng-if="q.type == 'checkbox'">
<p ng-repeat-start="a in q.answers">1 {{q.type}}
<input type={{q.type}}>{{a.text}}</input><br/>
</p>
<p ng-repeat-end></p>
</p>
<p ng-if="q.type == 'radio'">
<p ng-repeat-start="a in q.answers">2 {{q.type}}
<input type={{q.type}}>{{a.text}}</input><br/>
</p>
<p ng-repeat-end></p>
</p>
</div>
<p ng-repeat-end></p>
輸出顯示代碼正在執行每個if,如果他們都是真的。這會產生重複的checkbox /單選按鈕。
1 checkbox Voice calling.
1 checkbox Text messaging.
1 checkbox Data access
2 checkbox Voice calling.
2 checkbox Text messaging.
2 checkbox Data access
它應該是這樣的:
1 checkbox Voice calling.
1 checkbox Text messaging.
1 checkbox Data access
2 radio new question 1.
2 radio new question 2.
2 radio new question 3.
你可以分享「Q」對象的例子 –