这里是所复制的组件/问题的stackblitz。
我构建了一个自定义输入组件,该组件:
users[]
问题在于adding a result(input-tags.component)无法更新表单(app.component),我也不明白为什么。
input-tags.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
可以按预期方式调用,并且除窗体控件始终为null之外,其他都可以正常运行。为什么?
答案 0 :(得分:1)
错误似乎出在您的addTag()
函数中。您正在尝试访问typeaheadSource
中不存在的参数。将contact.userId
更改为contact.id
,您应该会很好。