【发布时间】:2019-09-14 11:36:09
【问题描述】:
我有一个带有 mat-select 下拉列表的编辑表单。当我转到编辑表单时,我想在下拉列表中设置所选项目。为此我调用服务来获取当前值。
我的html:
<mat-form-field appearance="outline">
<mat-select formControlName="organisationUnit" placeholder="Organisation Unit" [(value)]="selected">
<mat-option *ngFor="let unit of orgUnits" [value]="unit.id" >
{{unit.name}}
</mat-option>
</mat-select>
</mat-form-field>
我的ts:
ngOnInit() {
this.setupFirstFormGroup();
this.setupSecondFormGroup();
this.firstFormGroup.get('status').setValue(true);
this._route.params.subscribe(params => {
this.tenantAdminService.getUser(params.id).subscribe(res => {
this.firstFormGroup.get('first_name').setValue(res['first_name']);
this.firstFormGroup.get('last_name').setValue(res['last_name']);
this.tenantAdminService.getOrganizationUnit(res['organizationUnit']).subscribe(res => {
console.log("ORGUNIT", res);
this.selected = res['id'];
this.firstFormGroup.get('organisationUnit').setValue(res['id']);
});
});
});
}
目前它没有在下拉列表中设置值并且它是空的。它打印出值,但所选选项未显示为选中
【问题讨论】: