11// TODO(kara): prevent-close functionality
22
33import {
4+ AfterContentInit ,
45 Attribute ,
56 Component ,
67 ContentChildren ,
78 EventEmitter ,
89 Input ,
10+ OnDestroy ,
911 Output ,
1012 QueryList ,
1113 TemplateRef ,
@@ -17,6 +19,7 @@ import {MdMenuInvalidPositionX, MdMenuInvalidPositionY} from './menu-errors';
1719import { MdMenuItem } from './menu-item' ;
1820import { ListKeyManager } from '../core/a11y/list-key-manager' ;
1921import { MdMenuPanel } from './menu-panel' ;
22+ import { Subscription } from 'rxjs/Subscription' ;
2023
2124@Component ( {
2225 moduleId : module . id ,
@@ -27,10 +30,13 @@ import {MdMenuPanel} from './menu-panel';
2730 encapsulation : ViewEncapsulation . None ,
2831 exportAs : 'mdMenu'
2932} )
30- export class MdMenu implements MdMenuPanel {
33+ export class MdMenu implements AfterContentInit , MdMenuPanel , OnDestroy {
3134 private _keyManager : ListKeyManager ;
3235
33- // config object to be passed into the menu's ngClass
36+ /** Subscription to tab events on the menu panel */
37+ private _tabSubscription : Subscription ;
38+
39+ /** Config object to be passed into the menu's ngClass */
3440 _classList : Object ;
3541
3642 positionX : MenuPositionX = 'after' ;
@@ -45,11 +51,20 @@ export class MdMenu implements MdMenuPanel {
4551 if ( posY ) { this . _setPositionY ( posY ) ; }
4652 }
4753
54+ // TODO: internal
4855 ngAfterContentInit ( ) {
4956 this . _keyManager = new ListKeyManager ( this . items ) ;
50- this . _keyManager . tabOut . subscribe ( ( ) => this . _emitCloseEvent ( ) ) ;
57+ this . _tabSubscription = this . _keyManager . tabOut . subscribe ( ( ) => {
58+ this . _emitCloseEvent ( ) ;
59+ } ) ;
60+ }
61+
62+ // TODO: internal
63+ ngOnDestroy ( ) {
64+ this . _tabSubscription . unsubscribe ( ) ;
5165 }
5266
67+
5368 /**
5469 * This method takes classes set on the host md-menu element and applies them on the
5570 * menu template that displays in the overlay container. Otherwise, it's difficult
0 commit comments