Chartjs-Can a service get access to component's template

0👍

I think you’d need to make the following changes:

  1. Your service should only be responsible for getting the data and returning it to your component
  2. In your component, you shouldn’t directly reference the document. If you truly need to reference the element, you’d probably want to go about doing it like so:

In the HTML:

 <canvas #historicChart></canvas>

In the Component:

@ViewChild('historicChart') historicChart: ElementRef;

Then after you’ve gotten the data in the component:

const ctx = (this.historicChart.nativeElement as HTMLCanvasElement).getContext('2d')

Leave a comment