Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular 4 FormGroup-将父窗体控件传递给子组件_Javascript_Angular_Typescript_Angular Components_Angular Reactive Forms - Fatal编程技术网

Javascript Angular 4 FormGroup-将父窗体控件传递给子组件

Javascript Angular 4 FormGroup-将父窗体控件传递给子组件,javascript,angular,typescript,angular-components,angular-reactive-forms,Javascript,Angular,Typescript,Angular Components,Angular Reactive Forms,我用角反应形式来表示组和数组。我试图将表单字段拆分为子组件,但在将父表单控件传递给子组件时遇到问题,我觉得这应该很简单。我的父FormGroup是标题“binsForm”,我在模板中引用子组件,如: <app-child [parent]="binsForm"></app-child> 然后在子模板中引用该输入: <div class="fields-wrap" [formGroup]="parent"> <div class="input-wr

我用角反应形式来表示组和数组。我试图将表单字段拆分为子组件,但在将父表单控件传递给子组件时遇到问题,我觉得这应该很简单。我的父FormGroup是标题“binsForm”,我在模板中引用子组件,如:

<app-child [parent]="binsForm"></app-child>
然后在子模板中引用该输入:

<div class="fields-wrap" [formGroup]="parent">
   <div class="input-wrap">
      <label>Bin ID <span>*</span><input type="text" formControlName="id"></label>
   </div>
  <div class="clearfix"></div>
</div>

垃圾箱标识*
在以下内容中,您可以单击“编辑质量”,并在控制台中看到消息“找不到具有名称id的控件”


我遵循了此方法的教程,但不明白为什么子组件看不到表单组。

您需要在子组件上应用OnChanges以拾取新的父表单

导入一次更改

实现它
导出类ChildComponent实现OnInit,OnChanges{

ngOnChanges(changes) {
    console.log('changes', changes);
    this.parent = changes.parent;
}

您需要在子组件上应用OnChanges以拾取新的父窗体

导入一次更改

实现它
导出类ChildComponent实现OnInit,OnChanges{

ngOnChanges(changes) {
    console.log('changes', changes);
    this.parent = changes.parent;
}

我查看了您的代码,应用程序的子应用程序正在等待自己的表单,而您正在尝试注入没有子属性(如id、类型、子类型等)的父表单

因此,不要注入父窗体,只需尝试注入来自FormArray的子窗体(
BinFormArray
),如下所示:


我查看了您的代码,应用程序的子应用程序正在等待它自己的表单,而您正在尝试注入没有子属性(如id、类型、子类型等)的父表单

因此,不要注入父窗体,只需尝试注入来自FormArray的子窗体(
BinFormArray
),如下所示: