Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.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
Angular 子组件数据作为其他子组件的初始值。两个子组件之间的数据传递_Angular_Typescript - Fatal编程技术网

Angular 子组件数据作为其他子组件的初始值。两个子组件之间的数据传递

Angular 子组件数据作为其他子组件的初始值。两个子组件之间的数据传递,angular,typescript,Angular,Typescript,我有一个由父组件和两个子组件组成的角度项目。父组件是模态组件,而2个子组件是从用户/或表单接收数据的面板。使用父组件/模式中的“下一步”和“上一步”按钮执行两个子组件之间的导航。现在,我希望来自child1表单组件的数据成为child2组件的初始值。如果用户返回到第一个子表单组件并更改child1中的表单值,则更改将反映到child2表单初始值。我能够将数据从child1表单组件传递到父级,但很难将该数据作为初始值从父级组件传递到Child2表单。我尝试在ngOnInit中使用patchValu

我有一个由父组件和两个子组件组成的角度项目。父组件是模态组件,而2个子组件是从用户/或表单接收数据的面板。使用父组件/模式中的“下一步”和“上一步”按钮执行两个子组件之间的导航。现在,我希望来自child1表单组件的数据成为child2组件的初始值。如果用户返回到第一个子表单组件并更改child1中的表单值,则更改将反映到child2表单初始值。我能够将数据从child1表单组件传递到父级,但很难将该数据作为初始值从父级组件传递到Child2表单。我尝试在ngOnInit中使用patchValue将父数据传递给child2,但我得到了一个错误,如“name不是未定义的属性”。下面的图片显示了我真正想要实现的目标

代码如下:

export class Child2Component{
    @Input() person;

    child2Form : FormGroup; 
    ngOnit(){
       this.child2Form= this.fb.group({
           name: ''
       });
       this.child2Form.patchValue({
          name: this.person.name
       });
    }
}