22  ViewChild , 
33  Component , 
44  Input , 
5-   NgZone , 
65  QueryList , 
76  ElementRef , 
87  ViewEncapsulation , 
@@ -12,12 +11,14 @@ import {
1211  Optional , 
1312  AfterContentChecked , 
1413  AfterContentInit , 
14+   OnDestroy , 
1515}  from  '@angular/core' ; 
1616import  { RIGHT_ARROW ,  LEFT_ARROW ,  ENTER ,  Dir ,  LayoutDirection }  from  '../core' ; 
1717import  { MdTabLabelWrapper }  from  './tab-label-wrapper' ; 
1818import  { MdInkBar }  from  './ink-bar' ; 
19- import  'rxjs/add/operator/map ' ; 
19+ import  { Subscription }   from   'rxjs/Subscription ' ; 
2020import  { applyCssTransform }  from  '../core/style/apply-transform' ; 
21+ import  'rxjs/add/operator/map' ; 
2122
2223/** 
2324 * The directions that scrolling can go in when the header's tabs exceed the header width. 'After' 
@@ -51,7 +52,7 @@ const EXAGGERATED_OVERSCROLL = 60;
5152    '[class.mat-tab-header-rtl]' : "_getLayoutDirection() == 'rtl'" , 
5253  } 
5354} ) 
54- export  class  MdTabHeader  implements  AfterContentChecked ,  AfterContentInit  { 
55+ export  class  MdTabHeader  implements  AfterContentChecked ,  AfterContentInit ,   OnDestroy  { 
5556  @ContentChildren ( MdTabLabelWrapper )  _labelWrappers : QueryList < MdTabLabelWrapper > ; 
5657
5758  @ViewChild ( MdInkBar )  _inkBar : MdInkBar ; 
@@ -67,6 +68,9 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit {
6768  /** Whether the header should scroll to the selected index after the view has been checked. */ 
6869  private  _selectedIndexChanged  =  false ; 
6970
71+   /** Subscription to changes in the layout direction. */ 
72+   private  _directionChange : Subscription ; 
73+ 
7074  /** Whether the controls for pagination should be displayed */ 
7175  _showPaginationControls  =  false ; 
7276
@@ -102,9 +106,7 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit {
102106  /** Event emitted when a label is focused. */ 
103107  @Output ( )  indexFocused  =  new  EventEmitter ( ) ; 
104108
105-   constructor ( private  _zone : NgZone , 
106-               private  _elementRef : ElementRef , 
107-               @Optional ( )  private  _dir : Dir )  { } 
109+   constructor ( private  _elementRef : ElementRef ,  @Optional ( )  private  _dir : Dir )  { } 
108110
109111  ngAfterContentChecked ( ) : void { 
110112    // If the number of tab labels have changed, check if scrolling should be enabled 
@@ -149,6 +151,17 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit {
149151   */ 
150152  ngAfterContentInit ( )  { 
151153    this . _alignInkBarToSelectedTab ( ) ; 
154+ 
155+     if  ( this . _dir )  { 
156+       this . _directionChange  =  this . _dir . dirChange . subscribe ( ( )  =>  this . _alignInkBarToSelectedTab ( ) ) ; 
157+     } 
158+   } 
159+ 
160+   ngOnDestroy ( )  { 
161+     if  ( this . _directionChange )  { 
162+       this . _directionChange . unsubscribe ( ) ; 
163+       this . _directionChange  =  null ; 
164+     } 
152165  } 
153166
154167  /** 
@@ -373,10 +386,6 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit {
373386        ? this . _labelWrappers . toArray ( ) [ this . selectedIndex ] . elementRef . nativeElement 
374387        : null ; 
375388
376-     this . _zone . runOutsideAngular ( ( )  =>  { 
377-       requestAnimationFrame ( ( )  =>  { 
378-         this . _inkBar . alignToElement ( selectedLabelWrapper ) ; 
379-       } ) ; 
380-     } ) ; 
389+     this . _inkBar . alignToElement ( selectedLabelWrapper ) ; 
381390  } 
382391} 
0 commit comments