小编Pri*_*nka的帖子

“AbstractControl”类型缺少“FormGroup”类型中的以下属性:controls、registerControl、addControl、removeControl 和另外 3 个

我们最近从 ng 7.2.15 和 typescript 3.2.4 升级到了 angular v8.2.14 和 typescript v3.5.3。将表单组从父组件传递到子组件不再有效。

下面是我的子组件:子组件。ts

@Component({selector:'edit-overview'})
    export class ChildComponent implements OnInit {  
       public OverviewFormGroup : FormGroup
       constructor(private controlContainer: ControlContainer) {
       }

    ngOnInit() {
    this.OverviewFormGroup = <FormGroup>this.controlContainer.control;
    }
    }
Run Code Online (Sandbox Code Playgroud)

子组件.html

<div [formGroup] ='OverviewFormGroup'>
</div>
Run Code Online (Sandbox Code Playgroud)

和我的父组件

父组件.html

<div [formGroup]="Form1">
      <edit-overview [formGroup] = "Form1.controls.OverviewFormGroup">
      </edit-overview>
</div>
Run Code Online (Sandbox Code Playgroud)

父组件.ts

export class ParentComponent {
constructor(private readonly fb: FormBuilder) {
this.Form1 = this.fb.group({
 name: new FormControl('', [Validators.required]),
 OverviewFormGroup: new FormGroup({
        description: new FormControl('', [Validators.nullValidator])
      })
})
}
}
Run Code Online (Sandbox Code Playgroud)

它抛出此错误:“AbstractControl”类型缺少“FormGroup”类型中的以下属性:controls、registerControl、addControl、removeControl …

angular-reactive-forms angular8

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

angular-reactive-forms ×1

angular8 ×1