@@ -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' ,
@@ -335,6 +333,7 @@ export class MdSidenav implements AfterContentInit, OnDestroy {
335
333
host : {
336
334
'class' : 'mat-sidenav-container' ,
337
335
} ,
336
+ changeDetection : ChangeDetectionStrategy . OnPush ,
338
337
encapsulation : ViewEncapsulation . None ,
339
338
} )
340
339
export class MdSidenavContainer implements AfterContentInit {
@@ -363,7 +362,8 @@ export class MdSidenavContainer implements AfterContentInit {
363
362
private _right : MdSidenav | null ;
364
363
365
364
constructor ( @Optional ( ) private _dir : Directionality , private _element : ElementRef ,
366
- private _renderer : Renderer2 , private _ngZone : NgZone ) {
365
+ private _renderer : Renderer2 , private _ngZone : NgZone ,
366
+ private _changeDetectorRef : ChangeDetectorRef ) {
367
367
// If a `Dir` directive exists up the tree, listen direction changes and update the left/right
368
368
// properties to point to the proper start/end.
369
369
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