fix(charts): unsubscribe when destroy component

This commit is contained in:
KostyaDanovsky 2017-09-20 14:11:22 +03:00
parent 08851fdfed
commit 549be765f0
19 changed files with 152 additions and 57 deletions

View file

@ -1,4 +1,4 @@
import { Component } from '@angular/core';
import { Component, OnDestroy } from '@angular/core';
import { NbThemeService, NbColorHelper } from '@nebular/theme';
@Component({
@ -7,12 +7,13 @@ import { NbThemeService, NbColorHelper } from '@nebular/theme';
<chart type="bar" [data]="data" [options]="options"></chart>
`,
})
export class ChartjsBarComponent {
export class ChartjsBarComponent implements OnDestroy {
data: any;
options: any;
themeSubscription: any;
constructor(private theme: NbThemeService) {
this.theme.getJsTheme().subscribe(config => {
this.themeSubscription = this.theme.getJsTheme().subscribe(config => {
const colors: any = config.variables;
const chartjs: any = config.variables.chartjs;
@ -65,4 +66,8 @@ export class ChartjsBarComponent {
};
});
}
ngOnDestroy(): void {
this.themeSubscription.unsubscribe();
}
}