I have a problem with 2 way binding in mat-select component (angular material). In my ts file I have a option list and the binding variable (valueFromDB). Then I select value in mat-select component it's copy the value to valueFromDB variable. On another hand, On sceen load I would like to see in my mat-select component valueFromDB variable. How can I do it?
https://stackblitz.com/edit/angular-grupfc?file=app%2Fselect-value-binding-example.html
export class SelectValueBindingExample {
valueFromDB = new Option('Option2');
options = [new Option('Option1'), new Option('Option2'), new Option('Option3')];
}
export class Option{
name:string;
constructor(n:string){
this.name = n;
}
}
<mat-form-field>
<mat-select [(ngModel)]="valueFromDB" >
<mat-option>None</mat-option>
<mat-option *ngFor='let option of options' [value]='option' >{{option.name}}</mat-option>
</mat-select>
</mat-form-field>