As the title says, I have a reactive form that has multiple <mat-select> contained within. On initial form load, the initial option is not displayed even though form.value shows it is.
Pertinent component.ts:
export class DesJobInfoEditComponent implements OnInit {
...
currentJobData: IJob;
jobTypes: IJobType[];
...
constructor(private fb: FormBuilder) {
...
// Construct forms
this.createForm();
this.initializeForm();
}
createForm() {
this.editJobInfoForm = this.fb.group({
...
JobType: '', // mat-select
...
});
}
initializeForm() {
this.rebuildForm();
}
rebuildForm() {
this.editJobInfoForm.reset({
...
JobType: this.jobTypes[this.currentJobData.JobType].DisplayDesc,
...
});
}
}
Pertinent html:
<mat-form-field fxFlex>
<mat-label>Job Type</mat-label>
<mat-select formControlName="JobType" placeholder="Job Type">
<mat-option *ngFor="let jobType of jobTypes" value="jobType.value">
{{ jobType.DisplayDesc }}
</mat-option>
</mat-select>
</mat-form-field>
When the form loads, the selects do not display the initially selected option, however, they are set properly, apparently:
Form value { ... "JobType": "0 - Standard", ... }
All that displays on the form is the placeholder.
This seems like it should not be this difficult.
What am I doing wrong?
EDIT:
this.jobTypes is loaded when the module is loaded, and it is a BehaviorSubject that lives in my data service. I subscribe to it in the constructor of this component thusly:
this.data.jobTypes.subscribe(jobTypes => { this.jobTypes = jobTypes });
let jobType of jobTypes | async