【发布时间】:2018-03-01 14:46:34
【问题描述】:
我有两个组件: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}}
child.component.ts
<input type="text" name="thirdControl" [(ngModel)]="thirdControl" />
<input type="text" name="fourthControl" [(ngModel)]="fourthControl" />
现在,{{form.value | json}} 返回{ "firstControl": "", "secondControl": "" },很明显。我的问题是:有没有办法从子组件中继承表单控件?为 ParentComponent 获取 { "firstControl": "", "secondControl": "", "thirdControl": "", "fourthControl": "" } 的正确方法是什么?可能吗?
【问题讨论】:
标签: forms angular typescript angular-forms