@@ -4,12 +4,17 @@ import {
44 ViewChild ,
55 ElementRef ,
66 ViewEncapsulation ,
7- Directive , NgZone , Inject , Optional ,
7+ Directive ,
8+ NgZone ,
9+ Inject ,
10+ Optional ,
11+ OnDestroy ,
812} from '@angular/core' ;
913import { MdInkBar } from '../ink-bar' ;
1014import { MdRipple } from '../../core/ripple/index' ;
1115import { ViewportRuler } from '../../core/overlay/position/viewport-ruler' ;
12- import { MD_RIPPLE_GLOBAL_OPTIONS , RippleGlobalOptions } from '../../core/ripple/ripple' ;
16+ import { MD_RIPPLE_GLOBAL_OPTIONS , RippleGlobalOptions , Dir } from '../../core' ;
17+ import { Subscription } from 'rxjs/Subscription' ;
1318
1419/**
1520 * Navigation component matching the styles of the tab group header.
@@ -25,12 +30,19 @@ import {MD_RIPPLE_GLOBAL_OPTIONS, RippleGlobalOptions} from '../../core/ripple/r
2530 } ,
2631 encapsulation : ViewEncapsulation . None ,
2732} )
28- export class MdTabNavBar {
33+ export class MdTabNavBar implements OnDestroy {
34+ private _directionChange : Subscription ;
2935 _activeLinkChanged : boolean ;
3036 _activeLinkElement : ElementRef ;
3137
3238 @ViewChild ( MdInkBar ) _inkBar : MdInkBar ;
3339
40+ constructor ( @Optional ( ) private _dir : Dir ) {
41+ if ( _dir ) {
42+ this . _directionChange = _dir . dirChange . subscribe ( ( ) => this . _alignInkBar ( ) ) ;
43+ }
44+ }
45+
3446 /** Notifies the component that the active link has been changed. */
3547 updateActiveLink ( element : ElementRef ) {
3648 this . _activeLinkChanged = this . _activeLinkElement != element ;
@@ -40,10 +52,22 @@ export class MdTabNavBar {
4052 /** Checks if the active link has been changed and, if so, will update the ink bar. */
4153 ngAfterContentChecked ( ) : void {
4254 if ( this . _activeLinkChanged ) {
43- this . _inkBar . alignToElement ( this . _activeLinkElement . nativeElement ) ;
55+ this . _alignInkBar ( ) ;
4456 this . _activeLinkChanged = false ;
4557 }
4658 }
59+
60+ ngOnDestroy ( ) {
61+ if ( this . _directionChange ) {
62+ this . _directionChange . unsubscribe ( ) ;
63+ this . _directionChange = null ;
64+ }
65+ }
66+
67+ /** Aligns the ink bar to the active link. */
68+ private _alignInkBar ( ) : void {
69+ this . _inkBar . alignToElement ( this . _activeLinkElement . nativeElement ) ;
70+ }
4771}
4872
4973/**
0 commit comments