@@ -35,14 +35,14 @@ import {
3535} )
3636export class MdMenuTrigger implements AfterViewInit , OnDestroy {
3737 private _portal : TemplatePortal ;
38- private _overlay : OverlayRef ;
38+ private _overlayRef : OverlayRef ;
3939 menuOpen : boolean = false ;
4040
4141 @Input ( 'md-menu-trigger-for' ) menu : MdMenu ;
4242 @Output ( ) onMenuOpen = new EventEmitter ( ) ;
4343 @Output ( ) onMenuClose = new EventEmitter ( ) ;
4444
45- constructor ( private _overlayBuilder : Overlay , private _element : ElementRef ,
45+ constructor ( private _overlay : Overlay , private _element : ElementRef ,
4646 private _viewContainerRef : ViewContainerRef ) { }
4747
4848 ngAfterViewInit ( ) {
@@ -59,46 +59,63 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
5959 }
6060
6161 openMenu ( ) : Promise < void > {
62- return this . _overlay . attach ( this . _portal )
63- . then ( ( ) => this . _setMenuState ( true ) ) ;
62+ return this . _overlayRef . attach ( this . _portal )
63+ . then ( ( ) => this . _setIsMenuOpen ( true ) ) ;
6464 }
6565
6666 closeMenu ( ) : Promise < void > {
67- return this . _overlay . detach ( )
68- . then ( ( ) => this . _setMenuState ( false ) ) ;
67+ return this . _overlayRef . detach ( )
68+ . then ( ( ) => this . _setIsMenuOpen ( false ) ) ;
6969 }
7070
7171 destroyMenu ( ) : void {
72- this . _overlay . dispose ( ) ;
72+ this . _overlayRef . dispose ( ) ;
7373 }
7474
7575 // set state rather than toggle to support triggers sharing a menu
76- private _setMenuState ( bool : boolean ) : void {
77- this . menuOpen = bool ;
78- this . menu . _setClickCatcher ( bool ) ;
76+ private _setIsMenuOpen ( isOpen : boolean ) : void {
77+ this . menuOpen = isOpen ;
78+ this . menu . _setClickCatcher ( isOpen ) ;
7979 this . menuOpen ? this . onMenuOpen . emit ( null ) : this . onMenuClose . emit ( null ) ;
8080 }
8181
82+ /**
83+ * This method checks that a valid instance of MdMenu has been passed into
84+ * md-menu-trigger-for. If not, an exception is thrown.
85+ */
8286 private _checkMenu ( ) {
8387 if ( ! this . menu || ! ( this . menu instanceof MdMenu ) ) {
8488 throw new MdMenuMissingError ( ) ;
8589 }
8690 }
8791
92+ /**
93+ * This method creates the overlay from the provided menu's template and saves its
94+ * OverlayRef so that it can be attached to the DOM when openMenu is called.
95+ */
8896 private _createOverlay ( ) : void {
8997 this . _portal = new TemplatePortal ( this . menu . templateRef , this . _viewContainerRef ) ;
90- this . _overlayBuilder . create ( this . _getOverlayConfig ( ) )
91- . then ( overlay => this . _overlay = overlay ) ;
98+ this . _overlay . create ( this . _getOverlayConfig ( ) )
99+ . then ( overlay => this . _overlayRef = overlay ) ;
92100 }
93101
102+ /**
103+ * This method builds the configuration object needed to create the overlay, the OverlayState.
104+ * @returns OverlayState
105+ */
94106 private _getOverlayConfig ( ) : OverlayState {
95107 const overlayState = new OverlayState ( ) ;
96108 overlayState . positionStrategy = this . _getPosition ( ) ;
97109 return overlayState ;
98110 }
99111
112+ /**
113+ * This method builds the position strategy for the overlay, so the menu is properly connected
114+ * to the trigger.
115+ * @returns ConnectedPositionStrategy
116+ */
100117 private _getPosition ( ) : ConnectedPositionStrategy {
101- return this . _overlayBuilder . position ( ) . connectedTo (
118+ return this . _overlay . position ( ) . connectedTo (
102119 this . _element ,
103120 { originX : 'start' , originY : 'top' } ,
104121 { overlayX : 'start' , overlayY : 'top' }
0 commit comments