属性“订阅”没有初始值设定项,并且未在构造函数中明确分配

时间:2021-04-21 05:58:28

标签: angular10

在我的 Angular App 组件文件中。请找到组件 html 和 ts 文件的屏幕截图。你能告诉我订阅和图表选项有什么错误吗。

import { Component, OnInit } from '@angular/core';
import { Subscription } from 'rxjs';
import { ChartserviceService } from '../service/chartservice.service';
import { LineChartModel} from '../model/chartmodel.model';
import { EChartsOption } from 'echarts';

@Component({
  selector: 'app-linechart',
  templateUrl: './linechart.component.html',
  styleUrls: ['./linechart.component.css']
})
export class LinechartComponent implements OnInit {

  subscription: Subscription;
  chartOption: EChartsOption;
  //chartModel = new LineChartModel();


  constructor(public chartService : ChartserviceService) { }

  ngOnInit(): void {
    this.subscription = this.chartService.getChartData().subscribe(data => {
      this.basicLineChart(data);
    })
  }

  basicLineChart(echartData : LineChartModel[]){
    this.chartOption = {
      tooltip : {
        show : true
      },
      backgroundColor : 'transparent',
      xAxis: {
        type: 'category',
        data: echartData.map(m=>({
          value : m.name
        }))
    },
    yAxis: {
        type: 'value'
    },
    series: [{
        data: echartData.map(m=>({
          value : m.value
        })),
        type: 'line'
    }]
    }
  }

}

组件 TS 文件截图。

enter image description here

0 个答案:

没有答案