从父组件访问子组件中的表单组

时间:2018-08-15 14:12:05

标签: angular angular5

我正在尝试从父组件中的组件访问放置在组件内部的多个formGroup

@Component({
selector:'parent',
template:'<child1></child1>
<child2></child2>'
})

@Component({
selector:'child1',
template:'<div class="errors"></div>' //Need access to form1 and form2 in 
 this component
})

@Component({
selector:'child2',
template:'<form [formGroup]="form1"</form>
 <form [formGroup]="form2"</form>'
})

我需要访问“ child1”中“ child2”组件中的表单以获取验证错误

预先感谢

1 个答案:

答案 0 :(得分:0)

我将在父级中创建表单。那么您可以在子组件中注入FormGroupDirective。

<Label Text = "{Binding location.Description}" LineBreakMode="WordWrap"/>
<Button Text = "Play" Command="{Binding ClickedCommand}"/>    

表格为constructor(private fd: FormGroupDirective){}

相关问题