0

How to change text of id="itemid0" when id="buttonitemid0" is clicked?

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>

Manzer Hashmi
  • 73
  • 2
  • 4
  • 12

1 Answers1

0

Just store the index in a field in the component and then bind to this field

app.component.ts

clickedIdx :number;
changeText(index){
  this.clickedIdx = index;
}

app.component.html

<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>
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567