Angular2 - 无法绑定到'ngModel'而不是已知属性

时间:2016-10-27 12:28:52

标签: angular

在我的@ngModule中,我有导入FormsModule和ReactiveFOrmsModule。 但我仍然收到以下错误:

zone.js?1477571032896:355 Unhandled Promise rejection: Template parse errors:
Can't bind to 'ngModel' since it isn't a known property of 'p-editor'.
1. If 'p-editor' is an Angular component and it has 'ngModel' input, then verify that it is part of this module.
2. If 'p-editor' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message.

</p-editor>"): MainComponent@2:40
No provider for NgControl ("

[ERROR ->]<p-editor formControlName="description" [(ngModel)]="text" (onTextChange)="onTextChange($event)" [sty"): MainComponent@2:0

如果我尝试使用[(ngModel)]

进行绑定,这也会发生在输入等正常事情上

这是html:

<p-editor formControlName="description" [(ngModel)]="text" (onTextChange)="onTextChange($event)" [style]="{'height':'200px'}">

这是我使用的指南:没有hte [(ngModel)]

它可以正常工作
http://www.primefaces.org/primeng/#/editor

我的app.module.ts

imports: [
              BrowserModule,
              FormsModule,
              ReactiveFormsModule,

在主要组件模块中:

import { EditorModule, SharedModule, ButtonModule, TabMenuModule } from 'primeng/primeng';

并将它们添加到导入

2 个答案:

答案 0 :(得分:4)

只需在app.module.ts文件中添加FormsModule,如下所示,它对我有用,希望它也适合你

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';

@NgModule({
imports: [ BrowserModule, FormsModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})

export class AppModule { }

答案 1 :(得分:0)

除了 ngModel

之外,

添加 ngModelOptions 属性

[ngModelOptions]="{standalone: true}"