I'm working in Angular 7 and one of the requirements that I have is to create a mat-select with mat-icons. The issue I'm up against is I can either get the icons to show or I can get the option label to show but not both. What I need to do is be able to chain the value, but I got an error when I tried.
The mat-select is set up as so-
<button mat-raised-button type="button" name="button" color="primary" class="roundedButton">
<mat-select [(value)]="selected2">
<mat-select-trigger><mat-icon>{{selected2}}</mat-icon>{{selected2}}</mat-select-trigger>
<mat-option *ngFor="let food of foods" [value]="food.value">
<mat-icon>{{food.icon}}</mat-icon>{{food.viewValue}}
</mat-option>
</mat-select>
</button>
</mat-form-field>
I have placed the selected icon and label in the mat-select-trigger and the value to food.value.
The interface for the select is
export interface Food {
value: string;
viewValue: string;
icon: any;
}
and the select options are set up as
foods: Food[] = [
{value: 'steak-0', icon: 'add', viewValue: 'Steak'},
{value: 'pizza-1', icon: 'lock', viewValue: 'Pizza'},
{value: 'tacos-2', icon: 'search', viewValue: 'Tacos'}
];
public selected2 = 'steak-0';
If I change the value to be food.icon I can get the select options icon to appear as the selection. If I change value to food.viewValue I get the label of the option to appear.
How can I get both when a user makes a selection?
I have set up a Stackblitz to show the setup and issue in action.
Thank you in advance!