typescript - יוצא מן הכלל: לא נמצאה הערת Directive על AgGridNg2


למה הדוגמה הזו על TypeScript עם ag-grid לא עובדת?

יש שגיאה בקונסולה:

EXCEPTION: No Directive annotation found on AgGridNg2

קוד של cars.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 שבורה?

תשובה #1

הסתכלתי על ה-plunkr שלך. בגרסאות בטא, 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);
});

הנה דוגמה לשימוש ב-ag-grid עם TypeScript: https://github.com/helix46/ag-grid-angular2-beta-ts. הנה הקובץ בנוגע לקונפיגורציה: https://github.com/helix46/ag-grid-angular2-beta-ts/blob/master/src/boot.ts.

מקווה שזה עוזר לך, תיארי