【发布时间】:2017-01-29 06:04:55
【问题描述】:
我目前正在为我的应用程序使用 Angular2,现在我想将 ng2-table 添加到我的组件中。 ng2-Table on Git
我收到这个错误,忍不住问:
angular2-polyfills.js:487 Unhandled Promise rejection: Template parse errors:
Can't bind to 'colums' since it isn't a known property of 'ng-table'.
1. If 'ng-table' is an Angular component and it has 'colums' input, then
verify that it is part of this module.
2. If 'ng-table' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA"
to the '@NgModule.schema' of this component to suppress this message.
("
</div>-->
<ng-table [ERROR ->][colums]="columns" [rows]="rows" > </ng-table>
<div class="">
"): DeviceOverviewComponent@18:10 ;
Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:(…)
在我的 html 中,我得到了这个:
<ng-table [columns]="columns" [rows]="rows" > </ng-table>
我的组件是这样的:
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { DeviceService } from '../services/device.service';
@Component({
selector: 'device-overview',
templateUrl: 'dist/html/deviceoverview.component.html',
providers: [DeviceService],
})
export class DeviceOverviewComponent {
devices: any;
columns: any;
rows: any;
constructor(private deviceService: DeviceService, private router: Router) {
}
loadDevices() {
this.deviceService.getDevices()
.then((data) => {
this.devices = data
this.rows = this.devices
})
}
goToDevice(deviceName: string) {
this.router.navigateByUrl('/devices/' + deviceName)
}
ngOnInit() {
this.columns = [
{ title: "test", name: "id" }]
this.loadDevices();
}
}
我的 app.module 是这样的:
import { NgModule } from '@angular/core';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { Ng2TableModule } from 'ng2-table/ng2-table';
import { AppComponent } from './components/app.component';
import { DeviceOverviewComponent } from './components/deviceoverview.component'
import { DeviceService } from './services/device.service';
import { routing } from './app.routing';
@NgModule({
imports: [
Ng2TableModule,
BrowserModule,
FormsModule,
HttpModule,
routing,
],
declarations: [
DeviceOverviewComponent,
AppComponent,
],
providers:
[
{provide: LocationStrategy, useClass: HashLocationStrategy},
DeviceService,
],
bootstrap: [AppComponent]
})
export class AppModule { }
有人知道ng2-table的用法吗?还是有一个有效的替代方案,因为演示页面/使用文档现在不可用?
我找到了一些替代方案,但其中很多都在很久以前进行了最后一次提交,这可能是个问题,因为我一直在使用最新的 Angular2。
感谢您的阅读,不胜感激!
编辑: 我已经进入下一步了!
我需要添加
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core'
@NgModule({ ...,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
在我的 app.module.ts 中
现在我得到了带有“test”列的表头,并且我的行数据的 ID 属性显示正确。
即使来自 ng2-table 的演示也没有该导入。 我猜现在的文档和演示不是为新手制作的。 :/
【问题讨论】:
标签: html angular typescript