refactor(demo): unsubscribe when destroy component

This commit is contained in:
KostyaDanovsky 2017-09-20 14:31:06 +03:00
parent 549be765f0
commit cceabef8eb
12 changed files with 96 additions and 37 deletions

View file

@ -1,4 +1,4 @@
import { Component } from '@angular/core';
import { Component, OnDestroy } from '@angular/core';
import { NbThemeService } from '@nebular/theme';
@Component({
@ -6,13 +6,14 @@ import { NbThemeService } from '@nebular/theme';
styleUrls: ['./hero-buttons.component.scss'],
templateUrl: './hero-buttons.component.html',
})
export class HeroButtonComponent {
export class HeroButtonComponent implements OnDestroy {
themeName: string = 'default';
settings: Array<any>;
themeSubscription: any;
constructor(private themeService: NbThemeService) {
this.themeService.getJsTheme().subscribe(theme => {
this.themeSubscription = this.themeService.getJsTheme().subscribe(theme => {
this.themeName = theme.name;
this.init(theme.variables);
});
@ -115,4 +116,8 @@ export class HeroButtonComponent {
},
}];
}
ngOnDestroy() {
this.themeSubscription.unsubscribe();
}
}