在项目打包出现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]})))