angular - 从父组件访问子组件中的表单组
问题描述
我正在尝试从父组件中的组件访问放置在组件内的多个 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”组件中的表单以获取验证错误
提前致谢
解决方案
我会在父级中创建表单。然后您可以在子组件中注入 FormGroupDirective。
constructor(private fd: FormGroupDirective){}
形式是this.fd.form
推荐阅读
- java - 将 HTML 页面模板与用户数据一起存储在 DOCX 文件中后的外观
- vba - 下载大文件时VBA没有足够的内存资源错误
- dart - 从 Uint8List Dart 解析 int 和 float 值
- neo4j - neo4j 加载 csv 花费无限时间来执行我的查询
- typescript - 现在两只眼睛都没有出现,
- multi-index - 创建 2 级多索引
- amazon-web-services - 我们能否在不停机的情况下将 AWS redshift 从一个 VPC 迁移到另一个 VPC?
- javascript - 未捕获的 ReferenceError:未定义变量
- javascript - 反应路由中的错误 404
- android - Android 异常:cursor.getString(cursor....ColumnIndex("bucket_id")) 不能为空