0
NgOnInit関数を使用してサーバーからデータを取得する際に問題が発生しています。このデータで、私はmorris.jsを使ってプロットをペイントしたいが、私はそのデータを取得していない。Angular2 OnInit、サーバーからデータを取得しない
私はDBからすべての車の賠償額を取得し、その後、全額の賠償額を毎日プロットしたいと考えています。私は賠償の空配列を取得していると私は何をペイントすることはできません。
マイコード:
constructor(_router: Router, public http: Http, private _reparacionsService: ReparacioService) {
this.router = _router;
}
getReparacions() {
this._reparacionsService.getReparacions().subscribe(rep => this.reparacions = rep.json());
}
ngOnInit() {
this.getReparacions();
this.getLastWeek();
this.getReparacionsDia();
window['Morris'].Line({
element: 'repDaychart',
data: this.reparacionsDies,
xkey: 'data',
ykeys: ['totalReparacions'],
labels: ['totalReparacions'],
parseTime: false,
xLabels: "day"
});
}
私はすでにインポートとのOnInit宣言:
import {Component, OnInit} from 'angular2/core';
export class DashBoard implements OnInit
私が使用している角度ベータ17 感謝。
私はそれを試してみましたが、私はエラーを取得しています: はTypeError:プロパティを読み取ることができません未定義の「購読する」プロパティを読み取ることができません。DashBoard.ngOnInitで 未定義の「購読する」(dashboard.component.ts:36) でAppView._View_DashBoard_Host0.detectChangesInternal(DashBoard_Host.template.js:34)AppView.detectChangesで (angular2.dev.js:23638)AppView.detectContentChildrenChangesで (angular2.dev.js:23657)AppView._View_Home0.detectChangesInternalで ( Home.template.js:1338) –
申し訳ありません、 'getReparacions() 'に' return'を追加するのを忘れました。 –
ありがとう!今はエラーは出ませんが、プロットを描画しません。私はそれを探します。 –