我运行 ngFor,我需要循环内的某些属性通过添加 ngFor 索引来更改它的值。这意味着在 ngFor 中创建的每个 div 都将具有 uniq 属性值。 来源:
<div class="class1" *ngFor="let item of items; let i= index">
<div class="card-header" role="tab" id="Id">
<h1>Hello</h1>
</div>
我想绑定(bind) id 以获取它的值:当 index=0 时为 Id0。
<div class="card-header" role="tab" [attr.id]="Id+'i'"> Doesn't work :(
最佳答案
尝试:
<div class="card-header" role="tab" id="{{'Id'+i}}">
关于html - 如何将动态索引从 ngFor 添加到 html 属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42837214/