2
2
ViewChild ,
3
3
Component ,
4
4
Input ,
5
- NgZone ,
6
5
QueryList ,
7
6
ElementRef ,
8
7
ViewEncapsulation ,
@@ -12,12 +11,14 @@ import {
12
11
Optional ,
13
12
AfterContentChecked ,
14
13
AfterContentInit ,
14
+ OnDestroy ,
15
15
} from '@angular/core' ;
16
16
import { RIGHT_ARROW , LEFT_ARROW , ENTER , Dir , LayoutDirection } from '../core' ;
17
17
import { MdTabLabelWrapper } from './tab-label-wrapper' ;
18
18
import { MdInkBar } from './ink-bar' ;
19
- import 'rxjs/add/operator/map ' ;
19
+ import { Subscription } from 'rxjs/Subscription ' ;
20
20
import { applyCssTransform } from '../core/style/apply-transform' ;
21
+ import 'rxjs/add/operator/map' ;
21
22
22
23
/**
23
24
* 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;
51
52
'[class.mat-tab-header-rtl]' : "_getLayoutDirection() == 'rtl'" ,
52
53
}
53
54
} )
54
- export class MdTabHeader implements AfterContentChecked , AfterContentInit {
55
+ export class MdTabHeader implements AfterContentChecked , AfterContentInit , OnDestroy {
55
56
@ContentChildren ( MdTabLabelWrapper ) _labelWrappers : QueryList < MdTabLabelWrapper > ;
56
57
57
58
@ViewChild ( MdInkBar ) _inkBar : MdInkBar ;
@@ -67,6 +68,9 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit {
67
68
/** Whether the header should scroll to the selected index after the view has been checked. */
68
69
private _selectedIndexChanged = false ;
69
70
71
+ /** Subscription to changes in the layout direction. */
72
+ private _directionChange : Subscription ;
73
+
70
74
/** Whether the controls for pagination should be displayed */
71
75
_showPaginationControls = false ;
72
76
@@ -102,9 +106,7 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit {
102
106
/** Event emitted when a label is focused. */
103
107
@Output ( ) indexFocused = new EventEmitter ( ) ;
104
108
105
- constructor ( private _zone : NgZone ,
106
- private _elementRef : ElementRef ,
107
- @Optional ( ) private _dir : Dir ) { }
109
+ constructor ( private _elementRef : ElementRef , @Optional ( ) private _dir : Dir ) { }
108
110
109
111
ngAfterContentChecked ( ) : void {
110
112
// If the number of tab labels have changed, check if scrolling should be enabled
@@ -149,6 +151,17 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit {
149
151
*/
150
152
ngAfterContentInit ( ) {
151
153
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
+ }
152
165
}
153
166
154
167
/**
@@ -373,10 +386,6 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit {
373
386
? this . _labelWrappers . toArray ( ) [ this . selectedIndex ] . elementRef . nativeElement
374
387
: null ;
375
388
376
- this . _zone . runOutsideAngular ( ( ) => {
377
- requestAnimationFrame ( ( ) => {
378
- this . _inkBar . alignToElement ( selectedLabelWrapper ) ;
379
- } ) ;
380
- } ) ;
389
+ this . _inkBar . alignToElement ( selectedLabelWrapper ) ;
381
390
}
382
391
}
0 commit comments