我有一个FormGroup,其中包含2个FormControls“name”和“type” . Type是一个select html输入,其中包含使用ngFor循环生成的选项 . 所以当我编辑我的元素时,带有FormGroup的Component出现,它会加载我想要编辑的元素,并在名称输入字段中自动填充元素的名称 . 我想要做的是与类型字段相同 .
mycomponent.html
Name
Type
{{Type.Name}}
save
Back
mycomponent.ts
ngOnInit()
{
this.MyForm = new FormGroup
({
name: new FormControl(this.myElement.Name),
type: new FormControl() // myElement only has its Name and the Id of the type not the type name
})
}