I'm trying to pass div text in function using angular2
I have this in my template
<div (click)="logThis(this.text)">test</div>
and in component
logThis(x: any){
console.log(x);
}
If I'll put some text instead of this.text
it logs without any problem
I've tried this.value as well but it logs undefined
Other I've tried to add <div #test (click)="logThis(test.text)">test</div>
but same result
You can't use this
in the template of a component. Your template variable approach is correct though but I think there is no text
property:
<div (click)="logThis(div.innerText)" #div>test</div>
<div (click)="logThis(div.textContent)" #div>test</div>
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