Ionic2 - element._view未定义

时间:2017-04-28 08:16:23

标签: javascript angular ionic2 typescript2.0

我尝试将chart.js实现到离子项目中,我从firebase获取值..我使用subscribe推送数据..这是我的代码

export class HomePage {
  items: FirebaseListObservable<any[]>;
  itemsChart: FirebaseListObservable<any[]>;
  listArray: any[] = [];

  public lineChartType:string = 'line';
  public lineChartData:Array<any> = [{data: [], label: 'Grafik'}];
  public lineChartLabels:Array<any> = [];

  constructor(public navCtrl: NavController, af: AngularFire) {
    this.itemsChart = af.database.list('/kelembaban', {
       preserveSnapshot : true,
       query: {
         orderByKey: true,
         limitToLast: 10
       }
    }).map((array) => array.reverse()) as FirebaseListObservable<any[]>;

    this.itemsChart.subscribe(snapshots => {
      snapshots.forEach(snapshot => {
        this.lineChartLabels.push(snapshot.val().time);
        console.log(this.lineChartLabels);
        this.lineChartData[0]['data'].push(snapshot.val().value);
        console.log(this.lineChartData[0]['data']);
      });
    });
   }
}

我不知道我的代码有什么问题。建议

0 个答案:

没有答案