I have got simple question: how to create binding between button and textarea? I see that like:
html
<textarea [value]="test"> <button (click)="onclick($event)>
ts
onclick(event: Event) {
this.test = ($event.HowToChooseTarget as HTMLInputElement).value;
}
As you can see, the problem is to choose target element there. How to do this? Thank you for any help.
CodePudding user response:
There are multiple ways to achieve this.
With help of template ref variable
<textarea #test [value]="test"> <button (click)="onclick(test.value)>
Use ngModel and directly access the value in your component file with "this.test"
<textarea [(ngModel)]="test"> <button (click)="onclick($event)>