Skip to content

Instantly share code, notes, and snippets.

@arturovt
Created June 6, 2019 23:13
Show Gist options
  • Save arturovt/ed519ca9b9e7c28867c795d9c5c3dce5 to your computer and use it in GitHub Desktop.
Save arturovt/ed519ca9b9e7c28867c795d9c5c3dce5 to your computer and use it in GitHub Desktop.
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import * as Chart from 'chart.js';
@Component({
selector: 'app-line-chart',
template: `
<canvas #canvas></canvas>
`
})
export class LineChartComponent implements OnInit {
@ViewChild('canvas')
public canvas: ElementRef<HTMLCanvasElement> = null;
private options = {
...
};
public ngOnInit(): void {
const ctx = this.canvas.nativeElement.getContext('2d');
new Chart(ctx, this.options); // BAD!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment