It is possible pass the value of an id from a template, to function (AngulasJS2).
template: `
<div class="container" *ngFor="#mov of movs">
..//
<button class="btn btn-primary" type="button"
..//
(click)="test(id)" [id]="mov"
>
..//
..//
test(id: string) {
//test
var logo1: HTMLElement = document.getElementById(id);
..//
}
right now I'm using it and it works,
(click)="test(''+mov)" [id]="mov"
but with this code does not work.
(click)="test(id)" [id]="mov"
I'm sorry for my English
When you add a template variable like #elem
(on a native DOM element, not an Angular component or an element with a directive) you can use it as a reference to the element and then get the id from the element (elem.id
).
<div class="container" *ngFor="let mov of movs" >
..//
<button class="btn btn-primary" type="button" #elem
..//
(click)="test(elem.id)" [id]="mov"
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