我有两个组件:ParentComponent和ChildComponent:
parent.component.ts
<form #form="ngForm" (ngSubmit)="onSubmit(form)" novalidate>
<input type="text" name="firstControl" [(ngModel)]="firstControl" />
<input type="text" name="secondControl" [(ngModel)]="secondControl" />
<child-component>
</form>
{{form.value | json}}
Run Code Online (Sandbox Code Playgroud)
child.component.ts
<input type="text" name="thirdControl" [(ngModel)]="thirdControl" />
<input type="text" name="fourthControl" [(ngModel)]="fourthControl" />
Run Code Online (Sandbox Code Playgroud)
现在,{{form.value | json}}回归{ "firstControl": "", "secondControl": "" }并且很清楚.我的问题是:有没有办法从子组件形成enherit表单控件?获取{ "firstControl": "", "secondControl": "", "thirdControl": "", "fourthControl": "" }ParentComponent 的正确方法是什么?可能吗?