@@ -19,6 +19,8 @@ import {
1919 ViewChild ,
2020 ViewEncapsulation ,
2121 ElementRef ,
22+ InjectionToken ,
23+ Inject ,
2224} from '@angular/core' ;
2325import { MenuPositionX , MenuPositionY } from './menu-positions' ;
2426import { throwMdMenuInvalidPositionX , throwMdMenuInvalidPositionY } from './menu-errors' ;
@@ -29,6 +31,16 @@ import {Subscription} from 'rxjs/Subscription';
2931import { transformMenu , fadeInItems } from './menu-animations' ;
3032import { ESCAPE } from '../core/keyboard/keycodes' ;
3133
34+ /** Default `md-menu` options that can be overriden. */
35+ export interface MdMenuDefaultOptions {
36+ xPosition : MenuPositionX ;
37+ yPosition : MenuPositionY ;
38+ overlapTrigger : boolean ;
39+ }
40+
41+ /** Injection token to be used to override the default options for `md-menu`. */
42+ export const MD_MENU_DEFAULT_OPTIONS =
43+ new InjectionToken < MdMenuDefaultOptions > ( 'md-menu-default-options' ) ;
3244
3345@Component ( {
3446 moduleId : module . id ,
@@ -44,8 +56,8 @@ import {ESCAPE} from '../core/keyboard/keycodes';
4456} )
4557export class MdMenu implements AfterContentInit , MdMenuPanel , OnDestroy {
4658 private _keyManager : FocusKeyManager ;
47- private _xPosition : MenuPositionX = 'after' ;
48- private _yPosition : MenuPositionY = 'below' ;
59+ private _xPosition : MenuPositionX = this . _defaultOptions . xPosition ;
60+ private _yPosition : MenuPositionY = this . _defaultOptions . yPosition ;
4961
5062 /** Subscription to tab events on the menu panel */
5163 private _tabSubscription : Subscription ;
@@ -81,7 +93,7 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
8193 @ContentChildren ( MdMenuItem ) items : QueryList < MdMenuItem > ;
8294
8395 /** Whether the menu should overlap its trigger. */
84- @Input ( ) overlapTrigger = true ;
96+ @Input ( ) overlapTrigger = this . _defaultOptions . overlapTrigger ;
8597
8698 /**
8799 * This method takes classes set on the host md-menu element and applies them on the
@@ -105,7 +117,9 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
105117 /** Event emitted when the menu is closed. */
106118 @Output ( ) close = new EventEmitter < void > ( ) ;
107119
108- constructor ( private _elementRef : ElementRef ) { }
120+ constructor (
121+ private _elementRef : ElementRef ,
122+ @Inject ( MD_MENU_DEFAULT_OPTIONS ) private _defaultOptions : MdMenuDefaultOptions ) { }
109123
110124 ngAfterContentInit ( ) {
111125 this . _keyManager = new FocusKeyManager ( this . items ) . withWrap ( ) ;
0 commit comments