PrimeNG: 'p-table' is not a known element

I'm working on an Angular 6 application and I need to create a toggle table with PrimeNG 7.0.5, but I've got this problem when I tried to use <p-table>:

'p-table' is not a known element

Same problem when I want to use parameters as 'value' in < p-table >.

I am using the Documentation of the TurboTable here.

I have imported the TableModule in my app.module.ts.

app.module.ts

import { CommonModule, registerLocaleData } from '@angular/common';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { HttpModule } from '@angular/http';
import { NgModule, Pipe, PipeTransform, LOCALE_ID } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { AuthGuard } from './shared';
import { FormsModule } from '@angular/forms';
import { MessageComponent } from './message/message.component';
import { MessageService } from './message/message.service';
// imported it here
import { TableModule } from 'primeng/table';
import localeFr from '@angular/common/locales/fr';
registerLocaleData(localeFr);
export const createTranslateLoader = (http: HttpClient) => { return new TranslateHttpLoader(http, './assets/i18n/', '.json');
};
@NgModule({ imports: [ CommonModule, BrowserModule, BrowserAnimationsModule, HttpClientModule, FormsModule, HttpModule, TableModule, /* <-- added this */ TranslateModule.forRoot({ loader: { provide: TranslateLoader, useFactory: createTranslateLoader, deps: [HttpClient] } }), AppRoutingModule ], declarations: [AppComponent, MessageComponent], providers: [AuthGuard, MessageService, { provide: LOCALE_ID, useValue: 'fr-FR' }], bootstrap: [AppComponent]
})
export class AppModule { }

For the html, I've just tested the code with this:

<p-table></p-table>

I found nothing about this case on the net and on this version... Has somebody has ever had this problem?

3

3 Answers

import { TableModule } in the module in which component you are using it

2

First, please make sure you are generating angular and installing primeNG of the compatible version. I also got the same problem before I update my node.js. My node version is now. V12.16.2 and when I install primeNG I got a compatible version. So in part of my package.json is as follows:

"@angular/common": "9.0.4",
"@angular/compiler": "9.0.4",
"@angular/core": "9.0.4",

And the primeNG installed is of the following version:

"primeicons": "^2.0.0",
"primeng": "^9.0.5",

Then, importing the module should be in the nearest module to the html file.

import { TableModule } from 'primeng/table';

Hope it help.

Even after adding the CUSTOM_ELEMENTS_SCHEMA to my module and ensuring version compatibility, I was not able to get rid of the error. I looked further at the error message:

Error: src/app/ - error NG8001: 'p-table' is not a known element:
1. If 'p-table' is an Angular component, then verify that it is part of this module.
2. If 'p-table' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

And was able to figure the cause:MyComponent was using the PrimeNG table, and that it was not declared in the App Module. So all I had to do was add the MyComponent in declarations array for the module:

@NgModule({ declarations: [ AppComponent, MyComponent ], imports: [ BrowserModule, FormsModule, TableModule ], schemas: [CUSTOM_ELEMENTS_SCHEMA], bootstrap: [AppComponent]
})
export class AppModule { }

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like