Skip to content

Commit

Permalink
lazy create menu
Browse files Browse the repository at this point in the history
  • Loading branch information
kara committed Jul 21, 2016
1 parent 29ad153 commit 5a0fb83
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/components/menu/menu-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {

ngAfterViewInit() {
this._checkMenu();
this._createOverlay();
this.menu.close.subscribe(() => this.closeMenu());
}

Expand All @@ -59,11 +58,14 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
}

openMenu(): Promise<void> {
return this._overlayRef.attach(this._portal)
return this._createOverlay()
.then(() => this._overlayRef.attach(this._portal))
.then(() => this._setIsMenuOpen(true));
}

closeMenu(): Promise<void> {
if (!this._overlayRef) { return Promise.resolve(); }

return this._overlayRef.detach()
.then(() => this._setIsMenuOpen(false));
}
Expand Down Expand Up @@ -93,9 +95,11 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
* This method creates the overlay from the provided menu's template and saves its
* OverlayRef so that it can be attached to the DOM when openMenu is called.
*/
private _createOverlay(): void {
private _createOverlay(): Promise<any> {
if (this._overlayRef) { return Promise.resolve(); }

this._portal = new TemplatePortal(this.menu.templateRef, this._viewContainerRef);
this._overlay.create(this._getOverlayConfig())
return this._overlay.create(this._getOverlayConfig())
.then(overlay => this._overlayRef = overlay);
}

Expand Down

0 comments on commit 5a0fb83

Please sign in to comment.