angular - Angular如何在Childcomponent中获取FormControl的初始值
问题描述
如何在 ngOnInit 方法中获取自定义组件的初始设置 FormControl 值?
如果您像这样设置表单控件:
testControl = new FormControl("abc123");
然后将其绑定到 html 中的自定义组件,其属性如下:
<app-custom-component [formControl]="testControl"></app-custom-component>
如何在自定义组件的 ngOnInit() 方法中访问其初始值(“abc123”)?
我已经为我的自定义组件正确设置了 ControlValueAccessor 内容。
解决方案
根据我的理解,您想将值从父组件传递给子组件吗?
在子组件中
@Input('variable_in_child_component') 变量名
在父组件中您需要将该值传递给子组件
推荐阅读
- c# - 如何从我的项目访问我的 MongoDB 实例到我的 xunit 测试项目类?
- android - 我怎样才能将我的图像放在一个圆圈中而不出现在 Android Studio 上?
- python - 创建“压缩”字典
- php - 使用命名空间(PHP)从另一个类调用方法
- java - 在其他语言中状态为 200 时,在 Java 中登录后重定向 302
- php - 可以在类中获取数据但返回时只发送布尔值php PDO?
- c# - HtmlAgilityPack NullReferenceException 错误
- python - PySpark:连接数据类型为“Struc”的两列-> 错误:由于数据类型不匹配而无法解决
- java - 使按钮适应 JavaFX 中的窗口大小调整(重新定位)
- blob - 在复制活动期间或在 blob 数据集中指定名称时将日期时间动态附加到文件名