自定义组件绑定:“"没有值访问器 [英] Custom component binding: No value accessor for ''
问题描述
自RC2起,我使用自定义元素将表单更新为@angular/forms
.当我使用[(ngModel)]="myModel"
对其执行输入绑定时,我从angular获取了No value accessor for ''
,并且表单无法加载.该错误仅在输入绑定时发生.
I updated my form with a custom element to @angular/forms
as of RC2. When I perform an input binding on it using [(ngModel)]="myModel"
, I get No value accessor for ''
from angular and the form fails to load. The error only occurs with input binding.
以下是说明问题的工具: https://plnkr.co/edit/wxMsGuxr3GHMwNNoczT7?p =预览
Here's a plunker illustrating the issue: https://plnkr.co/edit/wxMsGuxr3GHMwNNoczT7?p=preview
值访问器通常可以正常工作(并且该模型使用RC1中的旧表格进行处理),因为FormBuilder
具有通过访问器接口正确设置的初始值.
The value accessor is generally working (and the model did with the old forms stuff in RC1) because the FormBuilder
has an initial value which is correctly set through the accessor interface.
问题似乎类似于 https://github.com/angular/angular/issues/7518 ,但引导代码中提供了form指令:
The issue seems similar to https://github.com/angular/angular/issues/7518 but the form directives are provided in the bootstrap code:
provideForms(),
{
provide: PLATFORM_DIRECTIVES,
useValue: [REACTIVE_FORM_DIRECTIVES],
multi: true
}
推荐答案
引导调用中缺少disableDeprecatedForms()
.看到这里: https://plnkr.co/edit/tk1rWdmXB7umkGPYK4Ho?p=preview
You are missing disableDeprecatedForms()
in the call to bootstrap. See here: https://plnkr.co/edit/tk1rWdmXB7umkGPYK4Ho?p=preview
这篇关于自定义组件绑定:“"没有值访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!