@@ -27,7 +27,7 @@ import {
27
27
import { Directionality , coerceBooleanProperty } from '../core' ;
28
28
import { FocusTrapFactory , FocusTrap } from '../core/a11y/focus-trap' ;
29
29
import { ESCAPE } from '../core/keyboard/keycodes' ;
30
- import { first } from '../core/rxjs/index' ;
30
+ import { first , takeUntil , startWith } from '../core/rxjs/index' ;
31
31
import { DOCUMENT } from '@angular/platform-browser' ;
32
32
import { merge } from 'rxjs/observable/merge' ;
33
33
@@ -372,13 +372,13 @@ export class MdSidenavContainer implements AfterContentInit {
372
372
}
373
373
374
374
ngAfterContentInit ( ) {
375
- // On changes, assert on consistency.
376
- this . _sidenavs . changes . subscribe ( ( ) => this . _validateDrawers ( ) ) ;
377
- this . _sidenavs . forEach ( ( sidenav : MdSidenav ) => {
378
- this . _watchSidenavToggle ( sidenav ) ;
379
- this . _watchSidenavAlign ( sidenav ) ;
375
+ startWith . call ( this . _sidenavs . changes , null ) . subscribe ( ( ) => {
376
+ this . _validateDrawers ( ) ;
377
+ this . _sidenavs . forEach ( ( sidenav : MdSidenav ) => {
378
+ this . _watchSidenavToggle ( sidenav ) ;
379
+ this . _watchSidenavAlign ( sidenav ) ;
380
+ } ) ;
380
381
} ) ;
381
- this . _validateDrawers ( ) ;
382
382
}
383
383
384
384
/** Calls `open` of both start and end sidenavs */
@@ -401,16 +401,17 @@ export class MdSidenavContainer implements AfterContentInit {
401
401
* is properly hidden.
402
402
*/
403
403
private _watchSidenavToggle ( sidenav : MdSidenav ) : void {
404
- merge ( sidenav . onOpenStart , sidenav . onCloseStart ) . subscribe ( ( ) => {
405
- // Set the transition class on the container so that the animations occur. This should not
406
- // be set initially because animations should only be triggered via a change in state.
407
- this . _renderer . addClass ( this . _element . nativeElement , 'mat-sidenav-transition' ) ;
408
- this . _changeDetectorRef . markForCheck ( ) ;
409
- } ) ;
404
+ takeUntil . call ( merge ( sidenav . onOpenStart , sidenav . onCloseStart ) , this . _sidenavs . changes )
405
+ . subscribe ( ( ) => {
406
+ // Set the transition class on the container so that the animations occur. This should not
407
+ // be set initially because animations should only be triggered via a change in state.
408
+ this . _renderer . addClass ( this . _element . nativeElement , 'mat-sidenav-transition' ) ;
409
+ this . _changeDetectorRef . markForCheck ( ) ;
410
+ } ) ;
410
411
411
412
if ( sidenav . mode !== 'side' ) {
412
- sidenav . onOpen . subscribe ( ( ) => this . _setContainerClass ( true ) ) ;
413
- sidenav . onClose . subscribe ( ( ) => this . _setContainerClass ( false ) ) ;
413
+ takeUntil . call ( merge ( sidenav . onOpen , sidenav . onClose ) , this . _sidenavs . changes ) . subscribe ( ( ) =>
414
+ this . _setContainerClass ( sidenav . opened ) ) ;
414
415
}
415
416
}
416
417
@@ -424,7 +425,7 @@ export class MdSidenavContainer implements AfterContentInit {
424
425
}
425
426
// NOTE: We need to wait for the microtask queue to be empty before validating,
426
427
// since both drawers may be swapping sides at the same time.
427
- sidenav . onAlignChanged . subscribe ( ( ) =>
428
+ takeUntil . call ( sidenav . onAlignChanged , this . _sidenavs . changes ) . subscribe ( ( ) =>
428
429
first . call ( this . _ngZone . onMicrotaskEmpty ) . subscribe ( ( ) => this . _validateDrawers ( ) ) ) ;
429
430
}
430
431
0 commit comments