@@ -22,12 +22,14 @@ import {
22
22
NgZone ,
23
23
OnDestroy ,
24
24
Inject ,
25
+ ChangeDetectorRef ,
25
26
} from '@angular/core' ;
26
27
import { Directionality , coerceBooleanProperty } from '../core' ;
27
28
import { FocusTrapFactory , FocusTrap } from '../core/a11y/focus-trap' ;
28
29
import { ESCAPE } from '../core/keyboard/keycodes' ;
29
30
import { first } from '../core/rxjs/index' ;
30
31
import { DOCUMENT } from '@angular/platform-browser' ;
32
+ import { merge } from 'rxjs/observable/merge' ;
31
33
32
34
33
35
/** Throws an exception when two MdSidenav are matching the same side. */
@@ -52,7 +54,6 @@ export class MdSidenavToggleResult {
52
54
@Component ( {
53
55
moduleId : module . id ,
54
56
selector : 'md-sidenav, mat-sidenav' ,
55
- // TODO(mmalerba): move template to separate file.
56
57
templateUrl : 'sidenav.html' ,
57
58
host : {
58
59
'class' : 'mat-sidenav' ,
@@ -324,9 +325,6 @@ export class MdSidenav implements AfterContentInit, OnDestroy {
324
325
@Component ( {
325
326
moduleId : module . id ,
326
327
selector : 'md-sidenav-container, mat-sidenav-container' ,
327
- // Do not use ChangeDetectionStrategy.OnPush. It does not work for this component because
328
- // technically it is a sibling of MdSidenav (on the content tree) and isn't updated when MdSidenav
329
- // changes its state.
330
328
templateUrl : 'sidenav-container.html' ,
331
329
styleUrls : [
332
330
'sidenav.css' ,
@@ -336,6 +334,7 @@ export class MdSidenav implements AfterContentInit, OnDestroy {
336
334
'class' : 'mat-sidenav-container' ,
337
335
'[class.mat-sidenav-transition]' : '_enableTransitions' ,
338
336
} ,
337
+ changeDetection : ChangeDetectionStrategy . OnPush ,
339
338
encapsulation : ViewEncapsulation . None ,
340
339
} )
341
340
export class MdSidenavContainer implements AfterContentInit {
@@ -367,7 +366,8 @@ export class MdSidenavContainer implements AfterContentInit {
367
366
_enableTransitions = false ;
368
367
369
368
constructor ( @Optional ( ) private _dir : Directionality , private _element : ElementRef ,
370
- private _renderer : Renderer2 , private _ngZone : NgZone ) {
369
+ private _renderer : Renderer2 , private _ngZone : NgZone ,
370
+ private _changeDetectorRef : ChangeDetectorRef ) {
371
371
// If a `Dir` directive exists up the tree, listen direction changes and update the left/right
372
372
// properties to point to the proper start/end.
373
373
if ( _dir != null ) {
@@ -408,9 +408,14 @@ export class MdSidenavContainer implements AfterContentInit {
408
408
* is properly hidden.
409
409
*/
410
410
private _watchSidenavToggle ( sidenav : MdSidenav ) : void {
411
- if ( ! sidenav || sidenav . mode === 'side' ) { return ; }
412
- sidenav . onOpen . subscribe ( ( ) => this . _setContainerClass ( true ) ) ;
413
- sidenav . onClose . subscribe ( ( ) => this . _setContainerClass ( false ) ) ;
411
+ merge ( sidenav . onOpenStart , sidenav . onCloseStart ) . subscribe ( ( ) => {
412
+ this . _changeDetectorRef . markForCheck ( ) ;
413
+ } ) ;
414
+
415
+ if ( sidenav . mode !== 'side' ) {
416
+ sidenav . onOpen . subscribe ( ( ) => this . _setContainerClass ( true ) ) ;
417
+ sidenav . onClose . subscribe ( ( ) => this . _setContainerClass ( false ) ) ;
418
+ }
414
419
}
415
420
416
421
/**
0 commit comments