Currently, I am encountering an issue while attempting to pre-select a value in a dropdown menu using Angular 5.
This is the HTML code:
<mat-form-field class="col-sm-3">
<mat-select placeholder="State" name="state [formControl]="stateFormControl" required>
<mat-option *ngFor="let state of states" value="{{state.key}}">{{state.name}}
</mat-option>
</mat-select>
<mat-error *ngIf="stateFormControl.hasError('required')">State is required
</mat-error>
</mat-form-field>
And this is the TypeScript code:
stateFormControl = new FormControl('', [
Validators.required
]);
this.vendorForm.controls["state"].setValue(this.state);
Despite setting a default value in the FormControl declaration, the dropdown menu does not reflect this default selection. Assistance on how to resolve this would be greatly appreciated.