Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 342
Dervillers Mattéo Avatar asked Dec 17 '22 18:12

Dervillers Mattéo


2 Answers

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

like image 130
Ved_Code_it Avatar answered Dec 28 '22 10:12

Ved_Code_it


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.

like image 41
Alvin Sanusi Avatar answered Dec 28 '22 11:12

Alvin Sanusi