angularcomponentsng2-smart-table

Unexpected module 'Ng2SmartTableModule' declared by the module 'AppModule'


I'm trying to learn ng2 smart table from this link and i got this error.

Uncaught Error: Unexpected module 'Ng2SmartTableModule' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation.

Here is the app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  //templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  //template: `<ng2-smart-table [settings]="settings"></ng2-smart-table>`
})
export class AppComponent {
  //title = 'app';
  settings = {
    columns: {
      id: {
        title: 'ID'
      },
      name: {
        title: 'Full Name'
      },
      username: {
        title: 'User Name'
      },
      email: {
        title: 'Email'
      }
    }
  };
}

And the app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { Ng2SmartTableModule } from 'ng2-smart-table';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent,
    Ng2SmartTableModule
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Can anyone help me fix this error?

Thanks in advance.


Solution

  • Since it is a module, You need to add inside imports not under declarations

    import { AppComponent } from './app.component';
    
    @NgModule({
      declarations: [
        AppComponent
    
      ],
      imports: [
        BrowserModule,
        Ng2SmartTableModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }