mat-select 内的模板插座不工作

template-outlet inside mat-select not working

我正在尝试使用 template-outlet 在 mat-select 中传递 #tmp,但我无法显示 select 选项。下面是我的代码和 link 到 stackblitz

    <mat-form-field>
        <mat-select 
           [ngModel]="selectedFoods" 
           (ngModelChane)="selectedFoods" placeholder="Favorite food" multiple>
        <ng-container *ngFor="let food of allfoods"
            [ngTemplateOutlet]="tmp"
            [ngTemplateOutletContext]="{ $implicit: food}">
        </ng-container>
        </mat-select>
    </mat-form-field>
    <ng-template #tmp let-food>
      <mat-option [value]="food.value">
        {{food.viewValue}}
      </mat-option>
    </ng-template>

https://stackblitz.com/edit/angular-mat-select-with-ngmodel-mujorn?embed=1&file=app/select-overview-example.ts

这似乎 work.I 认为重要的部分仍然是 <mat-options><mat-select> 中,而不是作为模板的一部分。

https://stackblitz.com/edit/mat-select-with-ngtemplateoutlet-example?devtoolsheight=33&file=app/select-overview-example.html

<mat-form-field>
    <mat-select>
       <mat-option *ngFor="let food of allfoods"  [value]="food.value">
          <ng-container [ngTemplateOutlet]="tmp" [ngTemplateOutletContext]="{food: food}">
          </ng-container>
       </mat-option>    
    </mat-select>
</mat-form-field>

<ng-template #tmp let-food="food">
    {{food.viewValue}} <b> From Tmp</b>
</ng-template>


Dropdown showing template value in select