2

I am creating template driven form by following this guide: https://angular.io/guide/forms

I need array of inputs e.g.

<input 
  *ngFor="let screenshot of screnshots" 
  [(ngModel)]="screenshot.id" 
  type="text" 
  name="screenshots[]" />

But in {{form.value}}, it is showing just one input value instead of multiple.

I want output of {{form.value}} like this : {screenshots:[1, 2, 3]}

I need this only in the form of array.

is it possible to implement in such way? or what is the best solution to achieve this goal?

1
  • use a model-driven form with formarray. Commented Jun 24, 2017 at 7:39

1 Answer 1

1

Input type text doesn't support multiple values like input type select or checkbox does, just give each input box a different name like this

<input 
  *ngFor="let screenshot of screnshots;let i = index" 
  [(ngModel)]="screenshot.id" 
  type="text" 
  [name]="'screenshot' + i"
Sign up to request clarification or add additional context in comments.

2 Comments

I don't agree! Input type text definitely support multiple values with same name by adding just [] with the name
Very interesting

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.