A lot of questions are discussing the way to set a default value to show in a "Select" control, here I am exposing an Angular 8 template driven forms case, where I cannot get the default value showing in the mat-select when the button is clicked, even if console.log shows the correct value:
<mat-select [formControl]="itemControl" required [(value)]="itemValue">
<mat-option>--</mat-option>
<mat-option *ngFor="let item of items" [value]="item">{{item}}</mat-option>
</mat-select>
My component code part is as follows:
export class MyComponent {
items: string[] = [''];
itemControl = new FormControl('', [Validators.required]);
itemValue: string = '';
myButtonClick(): void {
this.itemValue = this.getItems()[0]; <--- This returns the first element in a valid array
console.log(this.itemValue);
}
}
So what am I doing wrong ?