@@ -41,7 +41,7 @@ export const HIDE_ANIMATION = '195ms cubic-bezier(0.0,0.0,0.2,1)';
4141 host : {
4242 'role' : 'alert' ,
4343 '[@state]' : 'animationState' ,
44- '(@state.done)' : 'markAsExited ($event)'
44+ '(@state.done)' : 'onAnimationEnd ($event)'
4545 } ,
4646 animations : [
4747 trigger ( 'state' , [
@@ -58,7 +58,10 @@ export class MdSnackBarContainer extends BasePortalHost {
5858 @ViewChild ( PortalHostDirective ) _portalHost : PortalHostDirective ;
5959
6060 /** Subject for notifying that the snack bar has exited from view. */
61- private _onExit : Subject < any > = new Subject ( ) ;
61+ private onExit : Subject < any > = new Subject ( ) ;
62+
63+ /** Subject for notifying that the snack bar has finished entering the view. */
64+ private onEnter : Subject < any > = new Subject ( ) ;
6265
6366 /** The state of the snack bar animations. */
6467 animationState : SnackBarState = 'initial' ;
@@ -87,15 +90,21 @@ export class MdSnackBarContainer extends BasePortalHost {
8790 /** Begin animation of the snack bar exiting from view. */
8891 exit ( ) : Observable < void > {
8992 this . animationState = 'complete' ;
90- return this . _onExit . asObservable ( ) ;
93+ return this . onExit . asObservable ( ) ;
9194 }
9295
93- /** Mark snack bar as exited from the view . */
94- markAsExited ( event : AnimationTransitionEvent ) {
96+ /** Handle end of animations, updating the state of the snackbar . */
97+ onAnimationEnd ( event : AnimationTransitionEvent ) {
9598 if ( event . toState === 'void' || event . toState === 'complete' ) {
9699 this . _ngZone . run ( ( ) => {
97- this . _onExit . next ( ) ;
98- this . _onExit . complete ( ) ;
100+ this . onExit . next ( ) ;
101+ this . onExit . complete ( ) ;
102+ } ) ;
103+ }
104+ if ( event . toState === 'visible' ) {
105+ this . _ngZone . run ( ( ) => {
106+ this . onEnter . next ( ) ;
107+ this . onEnter . complete ( ) ;
99108 } ) ;
100109 }
101110 }
@@ -104,4 +113,9 @@ export class MdSnackBarContainer extends BasePortalHost {
104113 enter ( ) : void {
105114 this . animationState = 'visible' ;
106115 }
116+
117+ /** Returns an observable resolving when the enter animation completes. */
118+ _onEnter ( ) : Observable < void > {
119+ return this . onEnter . asObservable ( ) ;
120+ }
107121}
0 commit comments