如何更改id =" itemid0"的文字当id =" buttonitemid0"点击了吗?
app.component.ts
-----------------
bb = 'cat';
changeText(index){
}
app.component.html
-----------------------------
<div class="col-xs-2" *ngFor="let item of items;let k=index;">
<div class="col-xs-12" id="itemid{{index}}">aa</div>
<button type="button" id="buttonitemid{{index}}" (click)="changeText(index)">btnn</button>
</div>
答案 0 :(得分:0)
只需将索引存储在组件的字段中,然后绑定到此字段
即可clickedIdx :number;
changeText(index){
this.clickedIdx = index;
}
<div class="col-xs-2" *ngFor="let item of itmes"></div>
<div class="col-xs-2" *ngFor="let item of items;let k=index;">
<div class="col-xs-12" id="itemid{{index}}">aa</div>
<button type="button" id="buttonitemid{{clickedIdx}}" (click)="changeText(k)">btnn</button>
</div>