mirror of
https://github.com/akveo/ngx-admin.git
synced 2026-04-18 01:59:04 +02:00
refactor(demo): unsubscribe when destroy component
This commit is contained in:
parent
549be765f0
commit
cceabef8eb
12 changed files with 96 additions and 37 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { Component, HostBinding } from '@angular/core';
|
||||
import { Component, HostBinding, OnDestroy } from '@angular/core';
|
||||
import { NbThemeService, NbMediaBreakpoint, NbMediaBreakpointsService } from '@nebular/theme';
|
||||
|
||||
@Component({
|
||||
|
|
@ -12,7 +12,7 @@ import { NbThemeService, NbMediaBreakpoint, NbMediaBreakpointsService } from '@n
|
|||
</nb-card>
|
||||
`,
|
||||
})
|
||||
export class RoomsComponent {
|
||||
export class RoomsComponent implements OnDestroy {
|
||||
|
||||
@HostBinding('class.expanded')
|
||||
private expanded: boolean;
|
||||
|
|
@ -20,12 +20,13 @@ export class RoomsComponent {
|
|||
|
||||
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;
|
||||
});
|
||||
|
|
@ -56,4 +57,8 @@ export class RoomsComponent {
|
|||
private isSelected(roomNumber): boolean {
|
||||
return this.selected === roomNumber;
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.themeSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue