0

我有这段代码,它从烧瓶中获取数据到角度,并在角度高图中使用该数据。问题是我无法使用获取的数据,因为它总是提示错误 Property 'forecast' is used before its initialization.ts(2729), in my this.forecast. 下面是我的代码。

**Forecast.ts** (this is the class file):

export class Forecast {
    point:any;
    
    constructor(point){
        this.point = point;
    }
    
}

**try2.component.ts**

import { Component, OnInit } from '@angular/core';
import * as Highcharts from 'highcharts';
import { PredictService } from '../predict.service';
import { Forecast } from '../forecast'
@Component({
  selector: 'app-try2',
  templateUrl: './try2.component.html',
  styleUrls: ['./try2.component.css']
})
export class Try2Component implements OnInit {

  constructor(private ps: PredictService) { }
   forecast: Forecast;

  ngOnInit(): void {
     
  this.ps.readForecast().subscribe ((response) => 
  {
    this.forecast = response[0]["data"];

  })}
  highcharts = Highcharts;
  chartOptions: Highcharts.Options = {
      chart: {
         type: "spline"
      },
      title: {
         text: "Monthly Average Temperature"
      },
      subtitle: {
         text: "Source: WorldClimate.com"
      },
      xAxis:{
         categories:["Jan", "Feb", "Mar", "Apr", "May", "Jun",
            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
      },
      yAxis: {          
         title:{
            text:"Temperature °C"
         } 
      },
      tooltip: {
         valueSuffix:" °C"
      },
      series: [{
         type: 'spline',
         name: 'Tokyo',
         data: [this.forecast] //Error Occured here
      
     }]
   };

}
4

0 回答 0