1. 程式人生 > >(Angular Material)用Autocomplete打造帶層級分類的DropDown

(Angular Material)用Autocomplete打造帶層級分類的DropDown

height member style con 編寫 bsp input ont ports

效果如下圖

技術分享圖片

代碼實現

1、導入模塊

 import {MatAutocompleteModule} from ‘@angular/material/autocomplete‘;

 @NgModule({
  imports:[
  MatAutocompleteModule
  ]
 })

2、編寫List內容

this.memberNameList = [    {     onOffDist: ‘オン‘,      items: [‘丁1‘, ‘徐2‘, ‘僑3‘]    },    {      onOffDist: ‘オフ‘,      items: [‘趙4‘, ‘李5‘]
   } ];

3、html實現

<input type="text" name="memberName" matInput formControlName="memberName" [matAutocomplete]="memberName" [value]="costData.teamMember"/>    <mat-autocomplete style="font-size:12px; height: 30px;" #memberName="matAutocomplete">      <mat-optgroup *ngFor="let nameList of memberNameList" [label]="nameList.onOffDist">
       <mat-option style="font-size:12px; height: 30px;" *ngFor="let name of nameList.items"          [value]="name">          {{ name }}        </mat-option>      </mat-optgroup> </mat-autocomplete> 完成。

(Angular Material)用Autocomplete打造帶層級分類的DropDown