0

I'm trying to use an angular service to redraw ng2 chart. While using the graph component locally the graph getting redraw.

When I try to use angular shared service the graphs not redraw

anyone knows what I'm doing wrong?

Service injection is done with this tutorial: https://angular.io/tutorial/toh-pt4

Example for the graph taken from here https://github.com/valor-software/ng2-charts/blob/development/demo/src/app/components/charts/line-chart-demo.ts

https://github.com/valor-software/ng2-charts/blob/development/demo/src/app/components/charts/line-chart-demo.html

My code

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();

  }


}
hagai
  • 424
  • 1
  • 7
  • 13

0 Answers0