为什么带有ag网格的这个例子 on TypeSctipt不能工作?
控制台中有错误:
EXCEPTION: No Directive annotation found on AgGridNg2cars.ts代码,并在下面一行:
import {Component, View} from 'angular2/angular2'
import {CarsService} from './cars_service'
@Component({
selector: 'cars',
bindings: [CarsService]
})
@View({
template: `
<ag-grid-ng2 id="cars" class="ag-fresh"
[column-defs]="columnDefs" [row-data]="rowData">
</ag-grid-ng2>
`,
////////////////////////////////////
// Problem at this line
////////////////////////////////////
directives: [ag.grid.AgGridNg2]
})
export class Cars {
private columnDefs: Object[];
private rowData: Object[];
constructor(service: CarsService) {
this.columnDefs = [
{ headerName: "Make", field: "make" },
{ headerName: "Model", field: "model" },
{ headerName: "Price", field: "price" }
];
service.getCars().subscribe(
(res: Response) => {
this.rowData = res.json();
//console.log(this.rowData);
// TODO: Refresh table
});
}
}我是否必须导入AgGridNg2,以及如何导入?或者现在版本的Angular2 Beta坏了?
发布于 2016-01-20 09:09:00
我看了你的柱塞。在beta版本中,angular2/angular2现在是angular2/core。
也就是说,您似乎没有正确地初始化ag-grid。你应该试试这样的方法:
ag.grid.initialiseAgGridWithAngular2({ core: core });
bootstrap(App, [
HTTP_BINDINGS,
ROUTER_BINDINGS,
bind(ROUTER_PRIMARY_COMPONENT).toValue(App),
bind(LocationStrategy).toClass(HashLocationStrategy)
]);并从index.html文件中删除此块:
System.import("angular2/angular2").then(function(ng2) {
ag.grid.initialiseAgGridWithAngular2(ng2);
});下面是一个使用TypeScript:https://github.com/helix46/ag-grid-angular2-beta-ts的ag网格的示例。下面是有关配置的文件:https://github.com/helix46/ag-grid-angular2-beta-ts/blob/master/src/boot.ts。
希望它能帮到你,蒂埃里
https://stackoverflow.com/questions/34893234
复制相似问题