@@ -22,6 +22,8 @@ import {
2222 OnDestroy ,
2323 NgZone ,
2424 Renderer2 ,
25+ ChangeDetectionStrategy ,
26+ ChangeDetectorRef ,
2527} from '@angular/core' ;
2628import {
2729 RIGHT_ARROW ,
@@ -66,6 +68,7 @@ const EXAGGERATED_OVERSCROLL = 60;
6668 templateUrl : 'tab-header.html' ,
6769 styleUrls : [ 'tab-header.css' ] ,
6870 encapsulation : ViewEncapsulation . None ,
71+ changeDetection : ChangeDetectionStrategy . OnPush ,
6972 host : {
7073 'class' : 'mat-tab-header' ,
7174 '[class.mat-tab-header-pagination-controls-enabled]' : '_showPaginationControls' ,
@@ -74,7 +77,6 @@ const EXAGGERATED_OVERSCROLL = 60;
7477} )
7578export class MdTabHeader implements AfterContentChecked , AfterContentInit , OnDestroy {
7679 @ContentChildren ( MdTabLabelWrapper ) _labelWrappers : QueryList < MdTabLabelWrapper > ;
77-
7880 @ViewChild ( MdInkBar ) _inkBar : MdInkBar ;
7981 @ViewChild ( 'tabListContainer' ) _tabListContainer : ElementRef ;
8082 @ViewChild ( 'tabList' ) _tabList : ElementRef ;
@@ -137,13 +139,15 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit, OnDes
137139 private _elementRef : ElementRef ,
138140 private _ngZone : NgZone ,
139141 private _renderer : Renderer2 ,
142+ private _changeDetectorRef : ChangeDetectorRef ,
140143 @Optional ( ) private _dir : Directionality ) { }
141144
142145 ngAfterContentChecked ( ) : void {
143146 // If the number of tab labels have changed, check if scrolling should be enabled
144147 if ( this . _tabLabelCount != this . _labelWrappers . length ) {
145148 this . _updatePagination ( ) ;
146149 this . _tabLabelCount = this . _labelWrappers . length ;
150+ this . _changeDetectorRef . markForCheck ( ) ;
147151 }
148152
149153 // If the selected index has changed, scroll to the label and check if the scrolling controls
@@ -153,13 +157,15 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit, OnDes
153157 this . _checkScrollingControls ( ) ;
154158 this . _alignInkBarToSelectedTab ( ) ;
155159 this . _selectedIndexChanged = false ;
160+ this . _changeDetectorRef . markForCheck ( ) ;
156161 }
157162
158163 // If the scroll distance has been changed (tab selected, focused, scroll controls activated),
159164 // then translate the header to reflect this.
160165 if ( this . _scrollDistanceChanged ) {
161166 this . _updateTabScrollPosition ( ) ;
162167 this . _scrollDistanceChanged = false ;
168+ this . _changeDetectorRef . markForCheck ( ) ;
163169 }
164170 }
165171
@@ -207,6 +213,7 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit, OnDes
207213 _onContentChanges ( ) {
208214 this . _updatePagination ( ) ;
209215 this . _alignInkBarToSelectedTab ( ) ;
216+ this . _changeDetectorRef . markForCheck ( ) ;
210217 }
211218
212219 /**
@@ -224,7 +231,6 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit, OnDes
224231
225232 this . _focusIndex = value ;
226233 this . indexFocused . emit ( value ) ;
227-
228234 this . _setTabFocus ( value ) ;
229235 }
230236
@@ -259,6 +265,7 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit, OnDes
259265 // should be the full width minus the offset width.
260266 const containerEl = this . _tabListContainer . nativeElement ;
261267 const dir = this . _getLayoutDirection ( ) ;
268+
262269 if ( dir == 'ltr' ) {
263270 containerEl . scrollLeft = 0 ;
264271 } else {
@@ -274,6 +281,7 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit, OnDes
274281 _moveFocus ( offset : number ) {
275282 if ( this . _labelWrappers ) {
276283 const tabs : MdTabLabelWrapper [ ] = this . _labelWrappers . toArray ( ) ;
284+
277285 for ( let i = this . focusIndex + offset ; i < tabs . length && i >= 0 ; i += offset ) {
278286 if ( this . _isValidIndex ( i ) ) {
279287 this . focusIndex = i ;
@@ -314,7 +322,6 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit, OnDes
314322 // Mark that the scroll distance has changed so that after the view is checked, the CSS
315323 // transformation can move the header.
316324 this . _scrollDistanceChanged = true ;
317-
318325 this . _checkScrollingControls ( ) ;
319326 }
320327 get scrollDistance ( ) : number { return this . _scrollDistance ; }
@@ -341,9 +348,7 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit, OnDes
341348 * should be called sparingly.
342349 */
343350 _scrollToLabel ( labelIndex : number ) {
344- const selectedLabel = this . _labelWrappers
345- ? this . _labelWrappers . toArray ( ) [ labelIndex ]
346- : null ;
351+ const selectedLabel = this . _labelWrappers ? this . _labelWrappers . toArray ( ) [ labelIndex ] : null ;
347352
348353 if ( ! selectedLabel ) { return ; }
349354
@@ -386,6 +391,8 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit, OnDes
386391 if ( ! this . _showPaginationControls ) {
387392 this . scrollDistance = 0 ;
388393 }
394+
395+ this . _changeDetectorRef . markForCheck ( ) ;
389396 }
390397
391398 /**
@@ -401,6 +408,7 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit, OnDes
401408 // Check if the pagination arrows should be activated.
402409 this . _disableScrollBefore = this . scrollDistance == 0 ;
403410 this . _disableScrollAfter = this . scrollDistance == this . _getMaxScrollDistance ( ) ;
411+ this . _changeDetectorRef . markForCheck ( ) ;
404412 }
405413
406414 /**
0 commit comments