0

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"/>

1 Answer 1

1

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">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.