@@ -20,10 +20,9 @@ import {
20
20
AfterContentChecked ,
21
21
AfterContentInit ,
22
22
OnDestroy ,
23
- NgZone ,
24
23
Renderer2 ,
25
24
ChangeDetectionStrategy ,
26
- ChangeDetectorRef
25
+ ChangeDetectorRef ,
27
26
} from '@angular/core' ;
28
27
import { Directionality , Direction } from '@angular/cdk/bidi' ;
29
28
import { RIGHT_ARROW , LEFT_ARROW , ENTER } from '@angular/cdk/keycodes' ;
@@ -35,8 +34,6 @@ import {fromEvent} from 'rxjs/observable/fromEvent';
35
34
import { MdTabLabelWrapper } from './tab-label-wrapper' ;
36
35
import { MdInkBar } from './ink-bar' ;
37
36
import { CanDisableRipple , mixinDisableRipple } from '../core/common-behaviors/disable-ripple' ;
38
- import { RxChain , debounceTime } from '@angular/cdk/rxjs' ;
39
- import { Platform } from '@angular/cdk/platform' ;
40
37
41
38
/**
42
39
* The directions that scrolling can go in when the header's tabs exceed the header width. 'After'
@@ -117,15 +114,11 @@ export class MdTabHeader extends _MdTabHeaderMixinBase
117
114
118
115
private _selectedIndex : number = 0 ;
119
116
120
- /** subscription for the window resize handler */
121
- private _resizeSubscription : Subscription | null ;
122
-
123
117
/** The index of the active tab. */
124
118
@Input ( )
125
119
get selectedIndex ( ) : number { return this . _selectedIndex ; }
126
120
set selectedIndex ( value : number ) {
127
121
this . _selectedIndexChanged = this . _selectedIndex != value ;
128
-
129
122
this . _selectedIndex = value ;
130
123
this . _focusIndex = value ;
131
124
}
@@ -137,19 +130,10 @@ export class MdTabHeader extends _MdTabHeaderMixinBase
137
130
@Output ( ) indexFocused = new EventEmitter ( ) ;
138
131
139
132
constructor ( private _elementRef : ElementRef ,
140
- private _ngZone : NgZone ,
141
133
private _renderer : Renderer2 ,
142
134
private _changeDetectorRef : ChangeDetectorRef ,
143
- @Optional ( ) private _dir : Directionality ,
144
- platform : Platform ) {
135
+ @Optional ( ) private _dir : Directionality ) {
145
136
super ( ) ;
146
-
147
- if ( platform . isBrowser ) {
148
- // TODO: Add library level window listener https://goo.gl/y25X5M
149
- this . _resizeSubscription = RxChain . from ( fromEvent ( window , 'resize' ) )
150
- . call ( debounceTime , 150 )
151
- . subscribe ( ( ) => this . _checkPaginationEnabled ( ) ) ;
152
- }
153
137
}
154
138
155
139
ngAfterContentChecked ( ) : void {
@@ -197,16 +181,14 @@ export class MdTabHeader extends _MdTabHeaderMixinBase
197
181
* Aligns the ink bar to the selected tab on load.
198
182
*/
199
183
ngAfterContentInit ( ) {
200
- this . _realignInkBar = this . _ngZone . runOutsideAngular ( ( ) => {
201
- let dirChange = this . _dir ? this . _dir . change : observableOf ( null ) ;
202
- let resize = typeof window !== 'undefined' ?
203
- auditTime . call ( fromEvent ( window , 'resize' ) , 10 ) :
204
- observableOf ( null ) ;
205
-
206
- return startWith . call ( merge ( dirChange , resize ) , null ) . subscribe ( ( ) => {
207
- this . _updatePagination ( ) ;
208
- this . _alignInkBarToSelectedTab ( ) ;
209
- } ) ;
184
+ const dirChange = this . _dir ? this . _dir . change : observableOf ( null ) ;
185
+ const resize = typeof window !== 'undefined' ?
186
+ auditTime . call ( fromEvent ( window , 'resize' ) , 150 ) :
187
+ observableOf ( null ) ;
188
+
189
+ this . _realignInkBar = startWith . call ( merge ( dirChange , resize ) , null ) . subscribe ( ( ) => {
190
+ this . _updatePagination ( ) ;
191
+ this . _alignInkBarToSelectedTab ( ) ;
210
192
} ) ;
211
193
}
212
194
@@ -215,11 +197,6 @@ export class MdTabHeader extends _MdTabHeaderMixinBase
215
197
this . _realignInkBar . unsubscribe ( ) ;
216
198
this . _realignInkBar = null ;
217
199
}
218
-
219
- if ( this . _resizeSubscription ) {
220
- this . _resizeSubscription . unsubscribe ( ) ;
221
- this . _resizeSubscription = null ;
222
- }
223
200
}
224
201
225
202
/**
@@ -400,14 +377,18 @@ export class MdTabHeader extends _MdTabHeaderMixinBase
400
377
* should be called sparingly.
401
378
*/
402
379
_checkPaginationEnabled ( ) {
403
- this . _showPaginationControls =
380
+ const isEnabled =
404
381
this . _tabList . nativeElement . scrollWidth > this . _elementRef . nativeElement . offsetWidth ;
405
382
406
- if ( ! this . _showPaginationControls ) {
383
+ if ( ! isEnabled ) {
407
384
this . scrollDistance = 0 ;
408
385
}
409
386
410
- this . _changeDetectorRef . markForCheck ( ) ;
387
+ if ( isEnabled !== this . _showPaginationControls ) {
388
+ this . _changeDetectorRef . markForCheck ( ) ;
389
+ }
390
+
391
+ this . _showPaginationControls = isEnabled ;
411
392
}
412
393
413
394
/**
@@ -441,9 +422,9 @@ export class MdTabHeader extends _MdTabHeaderMixinBase
441
422
442
423
/** Tells the ink-bar to align itself to the current label wrapper */
443
424
private _alignInkBarToSelectedTab ( ) : void {
444
- const selectedLabelWrapper = this . _labelWrappers && this . _labelWrappers . length
445
- ? this . _labelWrappers . toArray ( ) [ this . selectedIndex ] . elementRef . nativeElement
446
- : null ;
425
+ const selectedLabelWrapper = this . _labelWrappers && this . _labelWrappers . length ?
426
+ this . _labelWrappers . toArray ( ) [ this . selectedIndex ] . elementRef . nativeElement :
427
+ null ;
447
428
448
429
this . _inkBar . alignToElement ( selectedLabelWrapper ) ;
449
430
}
0 commit comments