So I am having this issue on Angular 4.
I have this button in my html template markup:
<td><a class="btn btn-danger" (click)="delete()"><i class="fa fa-trash"></i></a></td>
I have the data assing to each td from a *ngFor, so I have the {{ data.id }} that I can use on this record, but how can I assign it to my delete method correctly, I tried using:
<td><a class="btn btn-danger" (click)="delete({{ data.id }})"><i class="fa fa-trash"></i></a></td>
<td><a class="btn btn-danger" (click)="delete(id)" [id]={{ data.id }}><i class="fa fa-trash"></i></a></td>
But none seem to work, so any advice or guidance would be greatly appreciated.
To get started using template reference variables, simply create a new Angular component or visit an existing one. To create a template reference variable, locate the HTML element that you want to reference and then tag it like so: #myVarName .
just pass data.id to delete function
<td><a class="btn btn-danger" (click)="delete(data.id)"><i class="fa fa-trash"></i></a></td>
and then in your delete function
delete(id : any){
console.log(id);
// perform your action
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With