Issue
I have a html button that has an id, and I want to send the id of the button, but not as writing the id on the field, I want to send it as this.id
but I cannot perform this.
<button (click)="changeEnergy(this.id)" id="flash" [ngClass]="!theme?'btnEnergy1':'btnEnergy2'">
<i id="flashIcon" class="fa-solid fa-bolt iconFlash"></i>
</button>
I tried by writing the id manually and it worked, but I want to send it like that as this.id
because the id of the element changes, it is not the same id, so I need to send the this.id
but I am not able to.
Solution
You can do it in the angular way by using a template variable referring to this button.
<button (click)="changeEnergy(flash.id)" id="flash"
[ngClass]="!theme?'btnEnergy1':'btnEnergy2'" #flash>
<i id="flashIcon" class="fa-solid fa-bolt iconFlash"></i>
</button>
Here, Note the #flash
which references the button element which we can use instead of this in pure js
Answered By - Vishnu Vinod
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.