html - Angular 2 嵌套 *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;">
推荐阅读
- python - Tkinter 函数“root.after()”不运行指定的函数
- excel - 将命名范围从表转置到另一个命名范围
- javascript - 检测点击外部组件反应钩子
- r - 如何绘制具有变量给定半径的散点图?
- python - 如何将我的烧瓶应用程序连接到我的 SQLite3 数据库?
- asp.net-mvc - 将字符串传递给匿名对象到 Tag Helper
- java - 已实现 hashCode() 但 retainAll() 仍然无法按预期工作
- macos - 即使在 mac 上安装了 gpg2,也找不到 gpg2 命令?(尝试安装 rvm)
- php - 了解 OOP 的概念
- java - 检查 Java 正则表达式中的特定字符