@@ -4,12 +4,17 @@ import {
4
4
ViewChild ,
5
5
ElementRef ,
6
6
ViewEncapsulation ,
7
- Directive , NgZone , Inject , Optional ,
7
+ Directive ,
8
+ NgZone ,
9
+ Inject ,
10
+ Optional ,
11
+ OnDestroy ,
8
12
} from '@angular/core' ;
9
13
import { MdInkBar } from '../ink-bar' ;
10
14
import { MdRipple } from '../../core/ripple/index' ;
11
15
import { 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' ;
13
18
14
19
/**
15
20
* Navigation component matching the styles of the tab group header.
@@ -25,12 +30,19 @@ import {MD_RIPPLE_GLOBAL_OPTIONS, RippleGlobalOptions} from '../../core/ripple/r
25
30
} ,
26
31
encapsulation : ViewEncapsulation . None ,
27
32
} )
28
- export class MdTabNavBar {
33
+ export class MdTabNavBar implements OnDestroy {
34
+ private _directionChange : Subscription ;
29
35
_activeLinkChanged : boolean ;
30
36
_activeLinkElement : ElementRef ;
31
37
32
38
@ViewChild ( MdInkBar ) _inkBar : MdInkBar ;
33
39
40
+ constructor ( @Optional ( ) private _dir : Dir , private _ngZone : NgZone ) {
41
+ if ( _dir ) {
42
+ this . _directionChange = _dir . dirChange . subscribe ( ( ) => this . _alignInkBar ( ) ) ;
43
+ }
44
+ }
45
+
34
46
/** Notifies the component that the active link has been changed. */
35
47
updateActiveLink ( element : ElementRef ) {
36
48
this . _activeLinkChanged = this . _activeLinkElement != element ;
@@ -40,10 +52,26 @@ export class MdTabNavBar {
40
52
/** Checks if the active link has been changed and, if so, will update the ink bar. */
41
53
ngAfterContentChecked ( ) : void {
42
54
if ( this . _activeLinkChanged ) {
43
- this . _inkBar . alignToElement ( this . _activeLinkElement . nativeElement ) ;
55
+ this . _alignInkBar ( ) ;
44
56
this . _activeLinkChanged = false ;
45
57
}
46
58
}
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 . _ngZone . runOutsideAngular ( ( ) => {
70
+ requestAnimationFrame ( ( ) => {
71
+ this . _inkBar . alignToElement ( this . _activeLinkElement . nativeElement ) ;
72
+ } ) ;
73
+ } ) ;
74
+ }
47
75
}
48
76
49
77
/**
0 commit comments