chris01
chris01

Reputation: 12311

Angular: common way to bind a input-variable

Lets say I need an input from a form into a variable. I do not need the other direction (change the variable in the component and make it visible in the template). So I need only one-way.

Is it more common to bind that input to the variable one-way and fetch it by a function

<input type="text" (keyup)="read ($event)"/>

OR

make ngModel even if I need it only one-way but it is more comfortable?

<input type="text" [(ngmModel)]="data"/>

Upvotes: 0

Views: 50

Answers (1)

user4676340
user4676340

Reputation:

In my opinion, the best way would be a form control : it is a completely unrelated variable that you can fetch and set to your will.

data = new FormControl('');
...
this.myVariable = data.value;
<input type="text" [formControl]="data">

Upvotes: 1

Related Questions