0👍
✅
I think you’d need to make the following changes:
- Your service should only be responsible for getting the data and returning it to your component
- 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')
Source:stackexchange.com