To incorporate an image within a <mat-option>
tag, you can simply nest an <img>
tag inside it. Use the ngClass
directive to set the image as a background for the selected option. Make sure to assign one class per option:
HTML
<mat-select [(value)]="selected" [ngClass]="selected">
<mat-option>None</mat-option>
<mat-option value="option1">Option 1
<img width="10" height="10" src="https://upload.wikimedia.org/wikipedia/commons/f/f9/Phoenicopterus_ruber_in_S%C3%A3o_Paulo_Zoo.jpg">
</mat-option>
<mat-option value="option2">Option 2
<img width="10" height="10" src="https://raw.githubusercontent.com/mdn/learning-area/master/html/multimedia-and-embedding/images-in-html/dinosaur_small.jpg">
</mat-option>
<mat-option value="option3">Option 3</mat-option>
</mat-select>
CSS:
.option1{
background: url("https://upload.wikimedia.org/wikipedia/commons/f/f9/Phoenicopterus_ruber_in_S%C3%A3o_Paulo_Zoo.jpg") center / contain no-repeat;
white-space: nowrap
}
.option2{
background: url("https://raw.githubusercontent.com/mdn/learning-area/master/html/multimedia-and-embedding/images-in-html/dinosaur_small.jpg") center / contain no-repeat;
white-space: nowrap;
display:inline
}
DEMO