Issue
I use this angular material select in my Angular 5 application:
<mat-form-field style="width:88%;">
<mat-select placeholder="Contact *" formControlName="contact">
<mat-option *ngFor="let contact of contacts" [value]="contact">
<mat-icon [ngStyle]="{'color': contact.color}">home</mat-icon>{{contact.institution}}
</mat-option>
</mat-select>
</mat-form-field>
On the select panel <mat-icon>
are listed as expected but if I select one option then the home icon does not appear in <mat-form-field>
How could I also view the home icon in <mat-form-field>
once selected?
Solution
This can be accomplished via the "mat-select-trigger" option. Documentation on the "mat-select" can be found here.
https://material.angular.io/components/select/api#MatSelectTrigger
Below should be a working example of what you are trying to do. Based on what you provided.
<mat-form-field style="width: 88%">
<mat-select placeholder="Contact *" formControlName="contact">
<mat-select-trigger>
<mat-icon>home</mat-icon> {{ contact.institution }}
</mat-select-trigger>
<mat-option *ngFor="let contact of contacts" [value]="contact">
<mat-icon [ngStyle]="{ color: contact.color }">home</mat-icon>{{ contact.institution }}
</mat-option>
</mat-select>
</mat-form-field>
And apply styles as necessary.
Answered By - cain4355
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.