Skip to content

Commit

Permalink
fix(layout): fix layout directives not hidden element in certain scen…
Browse files Browse the repository at this point in the history
…arios (#760)

* fix(layout): fix layout directives not hidden element in certain scenarios

when the route changes without the sidenav opening/closing, the visibility check wasnt toggled and the element wasnt hidden.

now we execute the visibility method in `ngAfterViewInit` always.

* chore(): add code block

* chore(): set fixed dependencies to zone.js and tslint
  • Loading branch information
emoralesb05 authored Jul 13, 2017
1 parent 9394017 commit d3c8d1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
18 changes: 15 additions & 3 deletions src/platform/core/layout/layout-toggle.class.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,7 +13,9 @@ export interface ILayoutTogglable {
close(): Promise<MdSidenavToggleResult>;
}

export abstract class LayoutToggle implements AfterViewInit {
export abstract class LayoutToggle implements AfterViewInit, OnDestroy {

private _toggleSubs: Subscription;

private _initialized: boolean = false;
private _disabled: boolean = false;
Expand Down Expand Up @@ -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;
}
}

/**
Expand Down

0 comments on commit d3c8d1b

Please sign in to comment.