如何在下拉列表中显示所选值?变量可以访问值,但不能显示它。
这是我在 ts 文件中的代码:
ngOnInit() {
this.buildItemForm(this.data.payload)
this.selectedValue = this.data.payload.survey_name;
// get all surveys
this.getSurvey();
}
buildItemForm(item) {
this.itemForm = this.fb.group({
deviceName: [item.deviceName || '', Validators.required],
survey_name: [item.survey_name || '', Validators.required],
synced_time: [item.synced_time || '', Validators.required],
isActive: [item.isActive || ''],
})
}
component.html 文件中的代码:
<div fxFlex="50" class="pr-1">
<mat-form-field class="full-width">
<mat-select placeholder="Survey Name" name="survey_name" [formControl]="itemForm.controls['survey_name']">
<mat-option
*ngFor="let survey of surveys"
[value]="survey">
{{survey.survey_name}}
</mat-option>
</mat-select>
</mat-form-field>
</div>