diff --git a/package.json b/package.json index 90b1718bcb..3fad810248 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "rxjs": "^5.2.0", "showdown": "1.6.4", "web-animations-js": "2.2.5", - "zone.js": "^0.8.12" + "zone.js": "0.8.12" }, "devDependencies": { "@angular/cli": "1.2.0", @@ -117,7 +117,7 @@ "rollup-plugin-node-resolve": "2.0.0", "semver": "5.2.0", "ts-node": "~2.0.0", - "tslint": "^5.2.0", + "tslint": "5.2.0", "typescript": "2.3.2" } } diff --git a/src/platform/core/layout/layout-toggle.class.ts b/src/platform/core/layout/layout-toggle.class.ts index 4d8a0369f5..12e79b27b0 100644 --- a/src/platform/core/layout/layout-toggle.class.ts +++ b/src/platform/core/layout/layout-toggle.class.ts @@ -1,4 +1,4 @@ -import { Input, HostBinding, HostListener, Renderer2, ElementRef, AfterViewInit } from '@angular/core'; +import { Input, HostBinding, HostListener, Renderer2, ElementRef, AfterViewInit, OnDestroy } from '@angular/core'; import { MdSidenavToggleResult, MdSidenav } from '@angular/material'; @@ -13,7 +13,9 @@ export interface ILayoutTogglable { close(): Promise; } -export abstract class LayoutToggle implements AfterViewInit { +export abstract class LayoutToggle implements AfterViewInit, OnDestroy { + + private _toggleSubs: Subscription; private _initialized: boolean = false; private _disabled: boolean = false; @@ -44,9 +46,19 @@ export abstract class LayoutToggle implements AfterViewInit { ngAfterViewInit(): void { this._initialized = true; - merge(this._layout.sidenav.onOpenStart, this._layout.sidenav.onCloseStart).subscribe(() => { + this._toggleSubs = merge(this._layout.sidenav.onOpenStart, this._layout.sidenav.onCloseStart).subscribe(() => { this._toggleVisibility(); }); + // execute toggleVisibility since the onOpenStart and onCloseStart + // methods might not be executed always when the element is rendered + this._toggleVisibility(); + } + + ngOnDestroy(): void { + if (this._toggleSubs) { + this._toggleSubs.unsubscribe(); + this._toggleSubs = undefined; + } } /**