我无法在角度 2 中为 md-select 设置值。我正在从构造函数填充选择列表,例如:
constructor() {
this.testService.getTypes()
.subscribe(result => {
if (result.code === 200) {
this.types = result.data;
}
}, error => {
this.router.navigate(['signin']);
});
}
这工作正常,数据在 md-select 上正确填充。然后我在运行一些查询后在 ngOnInit() 上设置值并将值设置为:
this.selectedValue = 'value';
我可以使用 {{selectedValue}} 正确访问 html 中的这个值。但是该值未加载到选择字段上。md-选择代码是:
<md-select placeholder="Type" [(ngModel)]="selectedValue" [formControl]="form.controls['typeName']" [required]="isRequired" style="width: 100%">
<md-option *ngFor="let type of types" [value]="type.typeId" [disabled]="type.disabled">
{{ type.typeName }}
</md-option>
任何帮助,将不胜感激。提前致谢!