我是 angular 的新手,需要帮助来实现动态垂直选项卡:
我正在使用我在 ngIf 条件的 ngFor 循环中定义的变量 i。我不知道如何在 ngIf 条件中使用变量 i。我尝试了下面的代码,但它似乎不起作用。
<div
class="pb-5"
*ngFor="let studentBatch of studentBatchList; let i = index"
>
<div
id="{{ 'tab-content-' + (3 + i) }}"
*ngIf="currTab == 'tab-content-(3+i)'"
>
{{ i + 3 }} <br />
{{ studentBatch.batchId }}
</div>
</div>
代码:
showtabcontent(id) {
debugger;
id = 'tab-content-' + id;
// this.currTab = 'tab-content-0';
this.currTab = id;
alert(id);
}
在*ngIf
i+3
被认为是一个字符串。在进行数学运算之前,您必须关闭单引号。
*ngIf="currTab == 'tab-content-' + (3 + i)"
完整示例:
<div class="pb-5" *ngFor="let studentBatch of studentBatchList; let i = index">
<div id="{{ 'tab-content-' + (3 + i) }}" *ngIf="currTab == 'tab-content-' + (3 + i)">
{{ i + 3 }} <br />
{{ studentBatch.batchId }}
</div>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句