试图在Angular 4项目中实现PrimeNG

时间:2017-05-22 15:42:03

标签: angular typescript primeng-datatable

我只想在Angular 4项目中实现PrimeNG库。我可以在我的dependecies和我的nodemodules文件夹中看到PrimeNG,但是当我做一个简单的时候:

        <p-dataTable >
           <p-column ></p-column>
           <p-column ></p-column>
           <p-column ></p-column>
           <p-column ></p-column>
       </p-dataTable>

这是我的控制台浏览器中的错误:

Unhandled Promise rejection: Template parse errors:
'p-column' is not a known element:
1. If 'p-column' is an Angular component, then verify that it is part of this module.
2. If 'p-column' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("

        <p-dataTable >
       [ERROR ->]<p-column ></p-column>
       <p-column ></p-column>
       <p-column ></p-column>
       "): ng:///AppModule/TableaudebordComponent.html@5:4

这是我的app.module.ts:

import { TableaudebordComponent } from './tableaudebord.component';
import { RouterModule, Routes } from '@angular/router'
import { ToggleComponent }  from './toggle.component';
import { HttpModule } from '@angular/http';
import { routeConfig } from './router-config';
import { AppComponent }  from './app.component';
import { UserService } from './user.service'; //  <-- #1 import  service

@NgModule({
 imports:      [ BrowserModule, HttpModule,     RouterModule.forRoot(routeConfig)
 ],
 declarations: [ AppComponent, DashboardComponent,          PageNotFoundComponent, NavbarComponent,PetitPaveInfraComponent,   PaveInfraComponent, PetitPaveAppliComponent, DashboardnextComponent, Dashboardnext2Component, Dashboardnext3Component,  PetitPaveProblemComponent, PaveProblemComponent, ToggleComponent,   TableaudebordComponent ],
providers: [ UserService ], 
bootstrap:    [ AppComponent ]
})
export class AppModule { }

1 个答案:

答案 0 :(得分:0)

确保导入您想要使用的PrimeNG功能所需的模块。在这种情况下,您要添加DataTableModule&amp;导入模块后,SharedModuleimports数组app.module.ts:来自primeng:

import {DataTableModule,SharedModule} from 'primeng/primeng';

imports: [..., DataTableModule, SharedModule]