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,18 @@ import { NbThemeService } from '@nebular/theme';
styleUrls: ['./kitten.component.scss'],
templateUrl: './kitten.component.html',
})
export class KittenComponent {
export class KittenComponent implements OnDestroy {
currentTheme: string;
themeSubscription: any;
constructor(private themeService: NbThemeService) {
this.themeService.getJsTheme().subscribe(theme => {
this.themeSubscription = this.themeService.getJsTheme().subscribe(theme => {
this.currentTheme = theme.name;
});
}
ngOnDestroy() {
this.themeSubscription.unsubscribe();
}
}