2017-02-16 64 views
1

我正在使用ng2-admin template並試圖在其中包含PrimeNG,但我很努力地添加它。在Angular 2 Webpack應用程序中不能包含PrimeNG

下面我在模板中做了包括PrimeNG變化

./src/vendor.browser.ts:

// Prime faces: http://www.primefaces.org/primeng/#/setup 
import 'primeng/primeng'; 

./src/app/app.module.ts:

import { ToggleButtonModule } from 'primeng/primeng'; 

@NgModule({ 
    bootstrap: [App], 
    declarations: [ 
    App 
    ], 
    imports: [ // import Angular's modules 
    ... 
    ... 
    ... 
    ToggleButtonModule 
    ], 
    providers: [ // expose our Services and Providers into Angular's dependency injection 
    ENV_PROVIDERS, 
    APP_PROVIDERS 
    ] 
}) 

./src/app/pages/dashboard/dashboard.component.ts:

import { ToggleButtonModule } from 'primeng/primeng'; 

./src/app/pages/dashboard/dashboard.html:

<p-toggleButton [(ngModel)]="checked"></p-toggleButton> 

我收到以下錯誤:

Can't bind to 'ngModel' since it isn't a known property of 'p-toggleButton'.

  1. If 'p-toggleButton' is an Angular component and it has 'ngModel' input, then verify that it is part of this module.
  2. If 'p-toggleButton' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message.

如果我刪除ngModel從標籤,我得到以下錯誤:

'p-toggleButton' is not a known element:

  1. If 'p-toggleButton' is an Angular component, then verify that it is part of this module.
  2. If 'p-toggleButton' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message.

將PrimeNG集成到Angular 2-Webpack應用程序中的正確方法是什麼?我在這裏錯過了什麼?

回答

0

我還沒有使用PrimeNG,但正在研究它。

但是,我認爲你的問題更容易解決。 ngModel來自Angular FormsModule。他們的文檔可以使這種依賴更加清晰。

將此添加到您的NgModule

import { FormsModule } from '@angular/forms'; 

@NgModule({ 
    imports: [ 
    ... 
    FormsModule 
    ], 
    ... 
}); 
相關問題