@@ -13,6 +13,8 @@ import {Subject} from 'rxjs/Subject';
1313export class OverlayRef implements PortalHost {
1414 private _backdropElement : HTMLElement = null ;
1515 private _backdropClick : Subject < any > = new Subject ( ) ;
16+ private _onAttach = new Subject < void > ( ) ;
17+ private _onDetach = new Subject < void > ( ) ;
1618
1719 constructor (
1820 private _portalHost : PortalHost ,
@@ -41,6 +43,7 @@ export class OverlayRef implements PortalHost {
4143 this . updateSize ( ) ;
4244 this . updateDirection ( ) ;
4345 this . updatePosition ( ) ;
46+ this . _onAttach . next ( ) ;
4447 this . _state . scrollStrategy . enable ( ) ;
4548
4649 // Enable pointer events for the overlay pane element.
@@ -65,6 +68,7 @@ export class OverlayRef implements PortalHost {
6568 // pointer events therefore. Depends on the position strategy and the applied pane boundaries.
6669 this . _togglePointerEvents ( false ) ;
6770 this . _state . scrollStrategy . disable ( ) ;
71+ this . _onDetach . next ( ) ;
6872
6973 return this . _portalHost . detach ( ) ;
7074 }
@@ -80,6 +84,9 @@ export class OverlayRef implements PortalHost {
8084 this . detachBackdrop ( ) ;
8185 this . _portalHost . dispose ( ) ;
8286 this . _state . scrollStrategy . disable ( ) ;
87+ this . _onDetach . next ( ) ;
88+ this . _onDetach . complete ( ) ;
89+ this . _onAttach . complete ( ) ;
8390 }
8491
8592 /**
@@ -96,6 +103,16 @@ export class OverlayRef implements PortalHost {
96103 return this . _backdropClick . asObservable ( ) ;
97104 }
98105
106+ /** Returns an observable that emits when the overlay has been attached. */
107+ onAttach ( ) : Observable < void > {
108+ return this . _onAttach . asObservable ( ) ;
109+ }
110+
111+ /** Returns an observable that emits when the overlay has been detached. */
112+ onDetach ( ) : Observable < void > {
113+ return this . _onDetach . asObservable ( ) ;
114+ }
115+
99116 /**
100117 * Gets the current state config of the overlay.
101118 */
0 commit comments