我正在使用material angular select component。當我點擊選擇器時,我可以看到圖標,但問題是當我選擇一個選項時,它只顯示值而不顯示圖標。如何在角度2/4材質設計選擇部件上添加圖像
在代碼重寫<md-option>
去除<img>
標籤並添加{{bodyStyle.viewValue}}
app.component.html
<div class="form-control form-control--center">
<md-select [(ngModel)]="selectedBodystyle" floatPlaceholder="never" name="bodyStyle">
<md-option *ngFor="let bodyStyle of bodyStyles" [value]="bodyStyle.value">
<img src="{{bodyStyle.icon}}" alt="{{bodyStyle.viewValue}}">
{{bodyStyle.viewValue}}
</md-option>
</md-select>
</div>
app.component.ts此刻
selectedBodystyle: string;
bodyStyles = [
{ value: 'Mercedez' , viewValue: 'Mercedez', icon: "http://lorempixel.com/50/50/transport/" },
{ value: 'Ferrari' , viewValue: 'Ferrari' , icon: "http://lorempixel.com/50/50/transport/" },
{ value: 'BMW' , viewValue: 'BMW' , icon: "http://lorempixel.com/50/50/transport/" }
];
更新
我試圖在viewValue
屬性添加圖像像
{ value: 'Ferrari' , viewValue: '<img src="http://lorempixel.com/50/50/transport/" alt="Ferrari">Ferrari' }
,但它加載以純文本格式的HTML它被選中後不顯示圖像
這是它選擇一個選項後顯示的內容,它刪除了圖片,它只顯示了viewValue
的內容
有一個開放的PR,這將簡化此爲您https://github.com/angular/material2/pull/3341。我不確定沒有組件工廠和一些詭計是可能的 –
我一直在嘗試一些如何在中傳遞圖像,因爲這是它被選中的內容。您的鏈接..謝謝 –