4

我尝试ngx-datatable在我的 angular 4 项目中使用 system.js 来加载模块,但它会引发如下错误:

无法绑定到“行”,因为它不是 ngx-datatable 的已知属性。
无法绑定到“列”,因为它不是 ngx-datatable 的已知属性。
ngx-datatable 不是已知元素:

我猜 system.js 没有正确加载模块,但我找不到有关如何执行此操作的工作演示。该文档也没有帮助。

system.config.js:

map: {
     ...
     '@swimlane/ngx-datatable': 'npm:@swimlane/ngx-datatable/release/index.js',
     ...
}

app.module.ts:

import { NgxDatatableModule } from '@swimlane/ngx-datatable';
...
imports: [
    ...
    NgxDatatableModule,
    ...
],

组件.html:

<ngx-datatable
     [rows]="rows"
     [columns]="columns">
</ngx-datatable>

组件.ts:

rows = [
    { name: 'Austin', gender: 'Male', company: 'Swimlane' },
    { name: 'Dany', gender: 'Male', company: 'KFC' },
    { name: 'Molly', gender: 'Female', company: 'Burger King' },
];
columns = [
    { prop: 'name' },
    { name: 'Gender' },
    { name: 'Company' }
];

包.json:

...
"@angular/animations": "^4.3.0",
"@angular/common": "^4.3.0",
"@angular/compiler": "^4.3.0",
"@angular/compiler-cli": "^4.3.0",
"@angular/core": "^4.3.0",
"@angular/forms": "^4.3.0",
"@angular/http": "^4.3.0",
"@angular/platform-browser": "^4.3.0",
"@angular/platform-browser-dynamic": "^4.3.0",
"@angular/platform-server": "^4.3.0",
"@angular/router": "^4.3.0",
"@angular/upgrade": "4.3.0",
"@swimlane/ngx-datatable": "^9.3.1",
...
4

3 回答 3

7

我安装它为我正常运行。请参考这个链接

Please import in App.module.ts like below:

    import { NgxDatatableModule } from '@swimlane/ngx-datatable';
@NgModule({
  imports: [
    NgxDatatableModule]});

请参阅 App.component.html

 <ngx-datatable class="material"
            [rows]="rows"
            [columns]="column">
          </ngx-datatable>
于 2019-05-29T12:58:40.080 回答
5

在括号中,尝试添加attrbeforerows或任何其他属性。应该是这样[attr.rows]="rows"等等[attr.columns]="columns"

于 2017-09-07T14:17:13.670 回答
1

我遇到了通过运行解决的相同问题

ng update

我不确定出了什么问题。

于 2021-04-11T16:37:36.263 回答