为了在角6的下拉设置的默认值

问题描述 投票:0回答:1

我有组件调用列表我在哪里显示在下拉列表中的customers我所有api如下图:

enter image description here

如何设置第一个顾客为默认?像这样:

enter image description here

DEMO

angular angular-material
1个回答
2
投票

只需添加这一点:

selectedCustomer = '01';

而在模板中使用[(ngModel)]

<div class="main-div">
  <h3>List</h3>
  <mat-form-field>
    <mat-select 
      placeholder="Select Customer" 
      [(ngModel)]="selectedCustomer">
      <mat-option 
        *ngFor="let customer of customers" 
        [value]="customer.id" 
        (click)="selected($event, customer.id)">
        {{customer.name}}
      </mat-option>
    </mat-select>
  </mat-form-field>
</div>

以下是为您的参考一Working Sample StackBlitz

© www.soinside.com 2019 - 2024. All rights reserved.