我正在尝试在特定字段的类型为某种类型时,向整个表单添加一个formGroup。我的添加formGroup的函数如下:
initSocial() {
const group = <FormGroup>this.cardForm;
group.addControl(
'social': this._fb.group({
'fb': new FormControl(this.currentCard.social.fb),
'yt': new FormControl(this.currentCard.social.yt),
'ig': new FormControl(this.currentCard.social.ig),
'tw': new FormControl(this.currentCard.social.tw),
})
)
}
现在,在“social”后面的冒号下,我收到了一个TypeScript错误,说期望有一个“,”。我还没有能够测试这个,看看addControl()是否会起作用。
我的触发initSocial的函数在ngOnInit中,代码如下:
if(this.currentCard.cardType === "brand"){
this.initSocial();
}
非常感谢您的帮助、提示和建议。
'social'
周围加上{}
了。请不要发布类似于“为什么这段代码不起作用”的问题。 - Reactgular