[英]Angular 2 Nested *ngFor
我目前正在嘗試將一些索引傳遞給函數,但第一個參數(ii)返回未定義。
<div *ngFor="let tab of screen.data.tabs; let index = i;">
<div *ngIf="tab.active">
<div *ngIf="tab.questions">
<div *ngFor="let question of tab.questions; let index = ii;">
<div class="scenarioContainerQUESTION">
<p [innerHtml]="question.text"></p>
<div *ngFor="let option of question.options; let iii = index;" class="option" [ngClass]="{'optionSelected': option.selected}">
<label [for]="ii+'_'+iii">{{option.text}}</label>
<input [id]="ii+'_'+iii" [name]="'group'+ii" type="radio" [value]="ii" (click)="optionClicked(ii,iii)" />
</div>
<button [ngClass]="{'fade': selectedOption == -1}" (click)="ManageSubmit()">SUBMIT</button>
</div>
</div>
</div>
</div>
</div>
您應該將索引值分配給變量,否則,
<div *ngFor="let tab of screen.data.tabs; let i= index;">
也
<div *ngFor="let question of tab.questions; let ii= index;">
查看ngFor的文檔。 綁定到index
的正確語法:
<li *ngFor="let item of items; index as i; trackBy: trackByFn">...</li>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.