@@ -15,7 +15,10 @@ import {Overlay, OVERLAY_PROVIDERS} from './overlay';
1515import { OverlayRef } from './overlay-ref' ;
1616import { TemplatePortal } from '../portal/portal' ;
1717import { OverlayState } from './overlay-state' ;
18- import { ConnectionPositionPair } from './position/connected-position' ;
18+ import {
19+ ConnectionPositionPair ,
20+ ConnectedOverlayPositionChange
21+ } from './position/connected-position' ;
1922import { PortalModule } from '../portal/portal-directives' ;
2023import { ConnectedPositionStrategy } from './position/connected-position-strategy' ;
2124import { Subscription } from 'rxjs/Subscription' ;
@@ -63,6 +66,7 @@ export class ConnectedOverlayDirective implements OnDestroy {
6366 private _open = false ;
6467 private _hasBackdrop = false ;
6568 private _backdropSubscription : Subscription ;
69+ private _positionSubscription : Subscription ;
6670
6771 @Input ( ) origin : OverlayOrigin ;
6872 @Input ( ) positions : ConnectionPositionPair [ ] ;
@@ -105,6 +109,7 @@ export class ConnectedOverlayDirective implements OnDestroy {
105109
106110 /** Event emitted when the backdrop is clicked. */
107111 @Output ( ) backdropClick = new EventEmitter < void > ( ) ;
112+ @Output ( ) positionChange = new EventEmitter < ConnectedOverlayPositionChange > ( ) ;
108113
109114 // TODO(jelbourn): inputs for size, scroll behavior, animation, etc.
110115
@@ -169,11 +174,29 @@ export class ConnectedOverlayDirective implements OnDestroy {
169174 const originPoint = { originX : pos . originX , originY : pos . originY } ;
170175 const overlayPoint = { overlayX : pos . overlayX , overlayY : pos . overlayY } ;
171176
172- return this . _overlay . position ( )
177+ const strategy = this . _overlay . position ( )
173178 . connectedTo ( this . origin . elementRef , originPoint , overlayPoint )
174179 . withDirection ( this . dir )
175180 . withOffsetX ( this . offsetX )
176181 . withOffsetY ( this . offsetY ) ;
182+
183+ this . _handlePositionChanges ( strategy ) ;
184+
185+ return strategy ;
186+ }
187+
188+ private _handlePositionChanges ( strategy : ConnectedPositionStrategy ) : void {
189+ for ( let i = 1 ; i < this . positions . length ; i ++ ) {
190+ strategy . withFallbackPosition (
191+ { originX : this . positions [ i ] . originX , originY : this . positions [ i ] . originY } ,
192+ { overlayX : this . positions [ i ] . overlayX , overlayY : this . positions [ i ] . overlayY }
193+ ) ;
194+ }
195+
196+ this . _positionSubscription = strategy . onPositionChange . subscribe (
197+ ( pos : ConnectedOverlayPositionChange ) => {
198+ this . positionChange . emit ( pos ) ;
199+ } ) ;
177200 }
178201
179202 /** Attaches the overlay and subscribes to backdrop clicks if backdrop exists */
@@ -214,6 +237,9 @@ export class ConnectedOverlayDirective implements OnDestroy {
214237 if ( this . _backdropSubscription ) {
215238 this . _backdropSubscription . unsubscribe ( ) ;
216239 }
240+ if ( this . _positionSubscription ) {
241+ this . _positionSubscription . unsubscribe ( ) ;
242+ }
217243 }
218244}
219245
0 commit comments