2017-10-20 98 views
1

我想从此link中学习ng2智能表,并且出现此错误。由模块'AppModule'声明的意外模块'Ng2SmartTableModule'

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

这里是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' 
 
     } 
 
    } 
 
    }; 
 
}

而且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 { }

谁能帮我解决THI错误?

在此先感谢。

回答

2

由于它是一个模块,你需要内部imports没有增加下declarations

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

@NgModule({ 
    declarations: [ 
    AppComponent 

    ], 
    imports: [ 
    BrowserModule, 
    Ng2SmartTableModule 
    ], 
    providers: [], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 
+0

感谢您的答案:) –

相关问题