'' angular2 没有值访问器 [英] No value accessor for '' angular2

查看:34
本文介绍了'' angular2 没有值访问器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Angular2 rc.4 和 PrimeNg 1.0.0.beta.9,但出现此错误:

I'm working with Angular2 rc.4 and PrimeNg 1.0.0.beta.9, and i'm getting this error:

platform-browser.umd.js:1900 Error: No value accessor for ''
    at new BaseException (common.umd.js:836)
    at _throwError (common.umd.js:3516)
    at setUpControl (common.umd.js:3493)
    at NgModel.ngOnChanges (common.umd.js:4103)
    at DebugAppView._View_ItemComponent1.detectChangesInternal (ItemComponent.template.js:1266)
    at DebugAppView.AppView.detectChanges (core.umd.js:12143)
    at DebugAppView.detectChanges (core.umd.js:12247)
    at DebugAppView.AppView.detectContentChildrenChanges (core.umd.js:12161)
    at DebugAppView._View_ItemComponent0.detectChangesInternal (ItemComponent.template.js:688)
    at DebugAppView.AppView.detectChanges (core.umd.js:12143)

所有使用 [(ngComponent)] 的 PrimeNG 组件都会发生这种情况,例如 p-dropdown 指令:

This happens with all the PrimeNG components that use [(ngComponent)], for example the p-dropdown directive:

<p-dropdown [options]="items" [(ngModel)]="item"></p-dropdown>

我已经关注了 Angular2 教程和 PrimeNG 展示,到目前为止一切正常,这是我遇到的第一个问题我无法解决.

I've follewed the Angular2 tutorial and the PrimeNG showcase, all worked fine until now, that's the first problem I faced that I can't solve.

如果我只删除部分

[(ngModel)]=... 

错误没有出现并且组件正确显示,即使我的项目列表也是如此.

the error doesn't appear and the component is correctly displayed, even with my list of items.

在我的 component.ts 文件中,我像其他几个人一样注入了指令:

In my component.ts file i've injected the directive like I've done with several others:

import {SelectItem, Dropdown} from 'primeng/primeng';
...
@Component({
...
directives:     [Dropdown],
})

我的问题和这个类似:ngmodele-no-value-accessor-for

但就我而言,自定义组件来自第三方库 (PrimeNG),我无法控制它

but in my case the custom component is from a third part library (PrimeNG) and I've not control over it

推荐答案

抛出的错误表明它正在使用 angular common.umd.js 模块中已弃用的 ngModel.它应该在新的 angular 表单模块中使用 ngModel.尝试禁用 main.ts 中已弃用的表单.

The error thrown indicates that it is using the ngModel from the angular common.umd.js module which have been deprecated. It should be using ngModel in the new angular forms module instead. Try disabling the deprecated forms in your main.ts.

示例:

import {bootstrap} from '@angular/platform-browser-dynamic';
import {App} from './app';
import { provideForms, disableDeprecatedForms } from '@angular/forms';

bootstrap(App, [provideForms(),
          disableDeprecatedForms()])
  .catch(err => console.error(err));

忘记添加...如果您查看 PrimeNG 下拉组件,您会看到它引用了新的角度形式.Github:dropdown.ts

Forgot to add... if you look at the PrimeNG dropdown component, you'll see that it is referencing the new angular forms. Github: dropdown.ts

这篇关于'' angular2 没有值访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆