意外的模块' Ng2SmartTableModule'由模块宣布的AppModule'

时间:2017-10-20 02:11:26

标签: angular components ng2-smart-table

我试图从这个link学习ng2智能表,我收到了这个错误。

未捕获的错误:意外的模块' Ng2SmartTableModule'由模块' AppModule'声明。请添加@ Pipe / @ Directive / @ Component注释。

这是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'
      }
    }
  };
}
&#13;
&#13;
&#13;

app.module.ts

&#13;
&#13;
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 { }
&#13;
&#13;
&#13;

任何人都可以帮我修复此错误吗?

提前致谢。

1 个答案:

答案 0 :(得分:6)

由于它是一个模块,您需要在 imports

下面的 declarations 内添加
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent

  ],
  imports: [
    BrowserModule,
    Ng2SmartTableModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
相关问题