繁体   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