I am trying to figure out how to display a mat-select in a dialog and have some of the mat-options preselected. I've created a simple example to demonstrate what I want to do:
In my example, I want to display a selectable list of colors, with a few of the colors preselected. I first create a mat-select and its contents (mat-options) by iterating over an array of strings in my dialog's TS file:
<mat-select placeholder="Colors" formControlName="selectedColors" multiple>
<mat-option *ngFor="let color of allColors" value="{{color}}">{{color}}</mat-option>
</mat-select>
This works just fine. In my dialog's TS file, I have the following arrays declared:
this.allColors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
this.defaultSelections = ['red', 'green', 'blue'];
Note the 2nd array, "defaultSelections": I want to have these items pre-selected when the dialog is displayed. I can't seem to find / figure out how to do this.
Thank you in advance for the help!