Reputation: 12311
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
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