我尝试使用角度服务来重绘ng2图表。 在本地使用图形组件时,图形获取重绘。
当我尝试使用角度共享服务时,图表不会重绘
谁知道我做错了什么?本教程完成了服务注入: https://angular.io/tutorial/toh-pt4
我的代码
CitiesComponent:
export class CitiesComponent implements OnInit, OnChanges {
constructor(private http: HttpClient, private globals: Globals, public graphService: GraphService) {}
HTML:
....
<button (click)="graphService.randomGraph()">CLICK</button>
....
GraphService:
import { Injectable } from '@angular/core';
import {PricesLineChartComponentComponent} from './prices-line-chart-component/prices-line-chart-component.component';
@Injectable()
export class GraphService {
constructor(public pricesComponent: PricesLineChartComponentComponent) { }
public randomGraph(){
this.pricesComponent.randomize();
}
}