K
K
Konstantin2020-06-29 21:02:14
Angular
Konstantin, 2020-06-29 21:02:14

How to populate an Angular select option list?

How to populate Angular select option list on click?

<div *ngFor="let order of orders"><select (click)="load(order.id)"></select></div>


How to populate the select list for each row with data from the server without modifying the original orders:

load(id: number) {
      this.service.load(id).subscribe((res) => {});
}


I use mat-select

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2020-06-30
@Junart1

What do you have in orders?

<mat-select formControlName="Orders">
<mat-option *ngFor="let order of orders" [value]="order.id">
 {{order.name}}
</mat-option>
</mat-select>

orders = [{id:1,name: "bla1"},{id:3,name: "bla2"},{id:3,name: "bla3"}]

If needed, select has (change) if it is necessary, for example, to send a request every time it changes...
(change)="doSmth($event.target.value)"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question