angular - Angular ControlValueAccessor onChanges 不更新表单控件值
问题描述
这是复制的组件/问题的堆栈闪电。
我构建了一个自定义输入组件:
- 采用用户对象数组进行预输入过滤
- 将您的选择显示为标签
- 表单控件值是选定用户的数组
users[]
问题是添加结果(input-tags.component)不会更新表单(app.component),我不明白为什么。
输入标签.component.ts
addTag(contact: any) {
...
this.onChange(this.tags); // update controller value
}
app.component.ts
this.form.controls['users'].valueChanges.subscribe(data => {
this.control = data; // always null
});
onChanges
按预期调用,一切正常,除了表单控件始终为空。为什么?
解决方案
错误似乎在您的addTag()
函数中。您正在尝试访问您的typeaheadSource
. 更改contact.userId
为contact.id
,您应该一切顺利。
推荐阅读
- html - 在一行上对齐不同的多个表单输入
- javascript - 地图内的地图 - Javascript
- go - 是否可以一次上传多个文件
- powershell - Filebrowser 文件名不适用于获取内容
- python - 在python中查找给定范围集之间的交集总数
- jestjs - JEST 从上下文 api 验证高阶组件 HOC 下组件的状态
- python - 在视频 URL 上调用 Opencv 的视频捕获在 Heroku 上不起作用
- c++ - 在 C++ 中从字符串中提取标记
- javascript - 如何从javascript中的另一个模块访问局部变量
- node.js - 使用 Jest 进行单元测试时出现“FIRESTORE 内部断言失败:意外状态”