@@ -20,6 +20,8 @@ import {
2020 ViewEncapsulation ,
2121 ElementRef ,
2222 ChangeDetectionStrategy ,
23+ InjectionToken ,
24+ Inject ,
2325} from '@angular/core' ;
2426import { AnimationEvent } from '@angular/animations' ;
2527import { MenuPositionX , MenuPositionY } from './menu-positions' ;
@@ -34,6 +36,16 @@ import {merge} from 'rxjs/observable/merge';
3436import { Observable } from 'rxjs/Observable' ;
3537import { Direction } from '../core' ;
3638
39+ /** Default `md-menu` options that can be overriden. */
40+ export interface MdMenuDefaultOptions {
41+ xPosition : MenuPositionX ;
42+ yPosition : MenuPositionY ;
43+ overlapTrigger : boolean ;
44+ }
45+
46+ /** Injection token to be used to override the default options for `md-menu`. */
47+ export const MD_MENU_DEFAULT_OPTIONS =
48+ new InjectionToken < MdMenuDefaultOptions > ( 'md-menu-default-options' ) ;
3749
3850@Component ( {
3951 moduleId : module . id ,
@@ -50,8 +62,8 @@ import {Direction} from '../core';
5062} )
5163export class MdMenu implements AfterContentInit , MdMenuPanel , OnDestroy {
5264 private _keyManager : FocusKeyManager ;
53- private _xPosition : MenuPositionX = 'after' ;
54- private _yPosition : MenuPositionY = 'below' ;
65+ private _xPosition : MenuPositionX = this . _defaultOptions . xPosition ;
66+ private _yPosition : MenuPositionY = this . _defaultOptions . yPosition ;
5567
5668 /** Subscription to tab events on the menu panel */
5769 private _tabSubscription : Subscription ;
@@ -96,7 +108,7 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
96108 @ContentChildren ( MdMenuItem ) items : QueryList < MdMenuItem > ;
97109
98110 /** Whether the menu should overlap its trigger. */
99- @Input ( ) overlapTrigger = true ;
111+ @Input ( ) overlapTrigger = this . _defaultOptions . overlapTrigger ;
100112
101113 /**
102114 * This method takes classes set on the host md-menu element and applies them on the
@@ -120,7 +132,9 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
120132 /** Event emitted when the menu is closed. */
121133 @Output ( ) close = new EventEmitter < void | 'click' | 'keydown' > ( ) ;
122134
123- constructor ( private _elementRef : ElementRef ) { }
135+ constructor (
136+ private _elementRef : ElementRef ,
137+ @Inject ( MD_MENU_DEFAULT_OPTIONS ) private _defaultOptions : MdMenuDefaultOptions ) { }
124138
125139 ngAfterContentInit ( ) {
126140 this . _keyManager = new FocusKeyManager ( this . items ) . withWrap ( ) ;
0 commit comments