What is the best practice to watch the value of an input HTML element? I need to dynamically add as much inputs as i want to. Hence, I cannot use ngModel
. At this point I'm using ElementRef
.
<div class="item">
<input type="text" id="firstName1">
<input type="text" id="lastName1">
</div>
I'm trying to create an object, where the values adapt to changes:
let user = {
firstName: ADAPT_TO_FIRSTNAME_VALUE,
lastName: ADAPT_TO_LASTNAME_VALUE
}
Solution Approach:
<form [formGroup]="user">
<input type="text" formControlName="firstName">
<input type="text" formControlName="lastName">
</form>
arr = new FormArray();
user;
create() {
this.user = new FormGroup({
firstName: new FormControl(),
lastName: new FormControl()
});
this.arr.push(user);
}