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();
}
}

View file

@ -1,4 +1,4 @@
import { Component } from '@angular/core';
import { Component, OnDestroy } from '@angular/core';
import { NbThemeService, NbMediaBreakpoint, NbMediaBreakpointsService } from '@nebular/theme';
@Component({
@ -6,17 +6,22 @@ import { NbThemeService, NbMediaBreakpoint, NbMediaBreakpointsService } from '@n
styleUrls: ['./typography.component.scss'],
templateUrl: './typography.component.html',
})
export class TypographyComponent {
export class TypographyComponent implements OnDestroy {
breakpoint: NbMediaBreakpoint;
breakpoints: any;
themeSubscription: any;
constructor(private themeService: NbThemeService,
private breakpointService: NbMediaBreakpointsService) {
this.breakpoints = breakpointService.getBreakpointsMap();
themeService.onMediaQueryChange()
this.themeSubscription = themeService.onMediaQueryChange()
.subscribe(([oldValue, newValue]) => {
this.breakpoint = newValue;
});
}
ngOnDestroy() {
this.themeSubscription.unsubscribe();
}
}