I'm wondering if is it possible to set an object as the value of a control :
TS:
this.form.patchValue({
myfield: this.object ? this.object : ''
});
HTML :
<mat-form-field>
<mat-select formControlName="myfield" required="true">
<mat-option *ngFor="let obj of objects" [value]="obj">
{{obj.name}}
</mat-option>
</mat-select>
</mat-form-field>
this does not work. but if patch the control with obj.id
(and update the value to obj.id
) it does work.
So my question is: is it normal that the fiels does not accept an object as the value? Or is it something wrong with my code? I didnt find any answer on the documentation. thanks.
EDIT : here is a stackblitz reproducing the issue (keep in mind that it's just for the sake of the example, in real life I get the data from Api's and resolvers. https://stackblitz.com/edit/angular-5ie6ar-8wy6ky