如何在 *ngFor 中使用 mat-select-trigger

Bha*_*an 8 angular-material angular

mat-option 有*ngFor并且我正在显示{{some text}}一个图标,因此,在选择任何一个选项时,{{some text}}和 图标文本都会显示在mat-form-field. 例如:如果我有一个文本"bbnh"和信息图标。选择此选项时,我希望它只显示"bbnh" image_for_the_above

我在 mat-options 中尝试过*ngFormat-select-trigger但它不起作用。

    <mat-form-field>
      <mat-select  placeholder="Select offer" formControlName="promo">
        <mat-select-trigger>
          {{ item.promo_code }} //Error occuring in this line
        </mat-select-trigger>
        <mat-option *ngFor="let item of promotions" [value]="item"
          >{{ item.promo_code }}
          <i class="material-icons">
            info
          </i>
        </mat-option>
      </mat-select>
    </mat-form-field>
Run Code Online (Sandbox Code Playgroud)

标识符'item'未定义。组件声明、模板变量声明和元素引用不包含这样的

Thi*_*gar 14

根据我的理解,我想这就是你要找的

<mat-form-field>
  <mat-select  placeholder="Select offer" formControlName="promo" [(value)]="selected">
    <mat-select-trigger>{{selected}}</mat-select-trigger>
    <mat-option *ngFor="let item of promotions" [value]="item"
      >{{ item.promo_code }}
      <i class="material-icons">
        info
      </i>
    </mat-option>
  </mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

这应该工作!如果您遇到任何错误,请在评论中告诉我们