In an Angular html template I have an select element with mat-select directive (Angular Material) which loads data from an object stored in a property called "selectedCriteria" in a service .ts file. Three types of object can be stored in the "selectedCriteria" property based on application logic and all of them have "name" variable of type String. So I want to load the object name in this select element.
Problem is when the app loads, the select element does not load/show the "selectedCriteria" because it's an object and not a string. I can use selectedCriteria.name to bind it with a string value, but that will add additional code to convert from object to string and vice versa for two way data binding. What is the solution to load an object in this select element during app startup?
<mat-form-field style="width: 45%; display: inline-block">
<mat-select
placeholder="Criteria"
[(value)]="reportService.selectedCriteria"
(valueChange)="reportService.filterSalesData()"
>
<mat-option
*ngFor="let criteria of reportService.criteriaList"
[value]="criteria"
>{{ criteria.name }}</mat-option
>
</mat-select>
</mat-form-field>