O
O
Ole892019-01-25 14:01:53
Angular
Ole89, 2019-01-25 14:01:53

How to pass the value of only one text field from the group to the component?

In the component template, I loop out a group of text fields:

<input  type="text" name="arr_text[]" [(ngModel)]="text_val">
<input  type="text" name="arr_text[]" [(ngModel)]="text_val">
<input  type="text" name="arr_text[]" [(ngModel)]="text_val">
<input  type="text" name="arr_text[]" [(ngModel)]="text_val">

In the component itself, of course, I declared the text_val variable, to which the entered value is successfully passed:
text_val: string;
However, when I enter a value in one text field, it is also entered in other text fields. For obvious reasons. And I need it to be entered only in where I enter.
How can I pass the value of only one of the text fields to the component? What type of variable to declare in the component? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
msdosx86, 2019-01-26
@Ole89

It is not clear why you need to change one value from several inputs, but keep

text_val = new FormControl();
<input  type="text" name="arr_text[]" [formControl]="text_val">
<input  type="text" name="arr_text[]" [formControl]="text_val">
<input  type="text" name="arr_text[]" [formControl]="text_val">
<input  type="text" name="arr_text[]" [formControl]="text_val">

Then take the valuethis.text_val.value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question