簡體   English   中英

以來自墊選項的墊選擇顯示圖像

[英]Display image in mat-select coming from mat-option

所以,我有一段HTML,其中包含一個mat-form-field,其中有一個mat-select和一個mat-option。 這些墊選項是從服務器生成的,當選擇了一個選項時,它們需要在墊選擇中顯示一個圖像(每個選項都有自己的圖像)

<mat-select>
    <ng-container
            *ngFor="let option of options">
            <mat-option>
                <!-- Image -->
                    <img
                        height="24px"
                        [src]="option[optionLabelImgKey]"/>
                !-- Label -->
                {{option[optionLabelKey] | translate}}
            </mat-option>
     </ng-container>
</mat-select>

每次選擇新選項時,我都想在mat-select中顯示optionLabel和圖像。

我已經閱讀過有關墊選擇觸發的信息,但對我來說沒有任何用。

嘗試把這個:

<img height="24px" src="option[optionLabelImgKey]"/>

可能是您的問題是,由於無法訪問img而無法顯示該img(錯誤的路由)。

順便說一下,我在stackblitz上創建了一個fork,其中包含mat-select內圖像列表的工作示例,您可以查看一下: https : //stackblitz.com/edit/angular-9txen8

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM