【问题标题】:Unexpected module 'Ng2SmartTableModule' declared by the module 'AppModule'模块“AppModule”声明的意外模块“Ng2SmartTableModule”
【发布时间】:2018-04-01 04:07:50
【问题描述】:

我正在尝试从此link 学习 ng2 智能表,但出现此错误。

未捕获的错误:模块“AppModule”声明的意外模块“Ng2SmartTableModule”。请添加@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'
      }
    }
  };
}

还有 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 { }

谁能帮我解决这个错误?

提前致谢。

【问题讨论】:

    标签: angular components ng2-smart-table


    【解决方案1】:

    由于是模块,需要在imports里面添加,而不是declarations

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

    【讨论】:

    • 感谢您的回答:)
    猜你喜欢
    • 1970-01-01
    • 2017-04-16
    • 2016-12-24
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-23
    相关资源
    最近更新 更多