我在我的component.html下拉需要当用户点击编辑按钮与值填充。现在所有的值,包括下拉的被检索但下拉是,用户才能看到的值点击的唯一控制。我想下拉显示,而用户点击它的价值。
下面是该component.html代码,
<mat-form-field>
<mat-select placeholder="Completed" formControlName="completed" #completed>
<mat-option value="true">Yes</mat-option>
<mat-option value="false">No</mat-option>
</mat-select>
</mat-form-field>
而这里的代码为我的编辑组件类,
ngOnInit() {
this.route.params.subscribe(params => {
this.id = parseInt(params.id);
this.blogService.getBooksById(this.id).subscribe(res => {
this.book = res;
this.completed = this.book[0].completed;
if (this.book[0].completed == true)
this.completed = "Yes"
else
this.completed = "No"
this.updateForm.get('title').setValue(this.book[0].title);
this.updateForm.get('comments').setValue(this.book[0].comments);
this.updateForm.get('completed').setValue(this.completed);
});
});
}
因此,有没有错误。我能够编辑和保存。但我不希望用户单击下拉,看看有什么值。下拉应显示completed
的值对于相应的书从表单中获取。该updateForm
是类型FormGroup
的。谢谢。