Select multiple inputs and store into an array in angular 5

fahad navaid khan

I am using angular 5 and I want to select multiple inputs from the dropdown and store the selected input into an array.

<select multiple  class="form-control " name="fea" ngModel size="3" >
  <option *ngFor="let feature of features | async" [ngValue]="feature">
       {{ feature.name }}
  </option>
</select>

Here I am selecting multiple inputs correctly but how can I store selected values in an array?

Any help will be appreciated!

Dheeraj Kumar

You can change option tag to below.

<option *ngFor="let feature of features | async" [ngValue]="feature" (click)="AddtoArray(feature.name)">
       {{ feature.name }}
  </option>

In you component,

array:any[]=[];

AddtoArray(feature:any){
    this.array.push(feature);
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to store inputs multiple times into local storage

分類Dev

Validate multiple select inputs as a group - Parsley

分類Dev

How to store multiple values in array

分類Dev

store result of select query into array variable

分類Dev

Store multiple textareas in different array's index

分類Dev

Angular multiple service provider as array

分類Dev

Hadoop multiple inputs

分類Dev

Hadoop multiple inputs

分類Dev

Addressing multiple inputs in shiny

分類Dev

Assigning Multiple Numerical Inputs

分類Dev

multiple line inputs in C

分類Dev

How to preview multiple inputs

分類Dev

Collecting inputs into the array

分類Dev

Add inputs values in array

分類Dev

Using Array or Series to select from multiple columns

分類Dev

select option to fetch other inputs

分類Dev

How to implement select all in angular material drop down angular 5

分類Dev

Store multiple row table into array to allow for user updates

分類Dev

ngrx angular9 getting array from store

分類Dev

Angular: How to use a Service to fetch data from server and store in an array?

分類Dev

Write JSON with multiple inputs in R

分類Dev

Checking if multiple inputs are of number type

分類Dev

Functors with multiple inputs in Standard ML

分類Dev

Hide multiple inputs with a single function

分類Dev

Display Json Array Angular 5 HttpClient

分類Dev

Observable of array with filter using Angular 5 with RxJS

分類Dev

Angular dynamic form group inputs

分類Dev

Have a constructor with inputs added to array

分類Dev

Taking unique inputs in an integer array