700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Angular使用ng build打包报错 Property 'setControl' does not exist on type 'AbstractControl'.解决方法

Angular使用ng build打包报错 Property 'setControl' does not exist on type 'AbstractControl'.解决方法

时间:2023-06-11 07:31:51

相关推荐

Angular使用ng build打包报错 Property 'setControl' does not exist on type 'AbstractControl'.解决方法

在项目打包出现setControl报错解决方法:

对于用setControl设置多层级表单的值的用法,会出现这个报错:

以下是正确的写法:

get services(): FormArray {return this.sltForm.get("Service") as FormArray;}this.services.setControl("SvcInetUrl", this.fb.array(sltService.SvcInetUrl.map(url =>this.fb.group({url: [url.url, Validators.required],urlType: [url.urlType, Validators.required]}))));

如果直接设置SvcInetUrl就会出现报错:(示例报错代码)

this.sltForm.setControl("Service", this.fb.group({SvcInetUrl: this.fb.array(sltService.svcInetUrls.map(url =>this.fb.group({url: [url.url, Validators.required],urlType: [url.urlType, Validators.required]})))

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。