angular - 模块 'Ng2SmartTableModule' 声明的意外模块 'AppModule'

标签 angular components ng2-smart-table

我正在尝试从这个 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 { }

谁能帮我解决这个错误?

提前致谢。

最佳答案

因为它是一个模块,你需要在 imports 里面添加,而不是在 declarations

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

@NgModule({
  declarations: [
    AppComponent

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

关于angular - 模块 'Ng2SmartTableModule' 声明的意外模块 'AppModule',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46841424/

相关文章:

angularjs - 每当添加新行时,如何在 ng2-smart-table 中使用 post 方法?

angular - ng2-smart-table 在编辑单击时打开弹出窗口

Angular2RC4-Primeng 菜单栏 routerlink 在点击后不转到我的路线

angular - 有什么特别的吗?类型 'Node' 无法转换为类型 'ChildNode'

带有 rxjs 的 Angular HttpClient

java - 如何使组件在面板的特定区域内居中

javascript - 将数据从模型提取到变量

cakephp - CakePHP 中的自动登录

javascript - 组件的 JavaScript 不会在使用 React 路由器的路由上执行

angular - ng2-smart-table 中的复选框