Skip to content

Commit ae46810

Browse files
ambaumanntinayuangao
authored andcommitted
refactor(tabs-demo): replace active link index with active router link isActive property (#4729)
Motivation is to remove the current comment "can be removed if routerLink exposes if it is active". Current router link implementation does allow the itActive flag.
1 parent 3212411 commit ae46810

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

src/demo-app/tabs/tabs-demo.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ <h1>Tab Nav Bar</h1>
55
<a md-tab-link
66
*ngFor="let tabLink of tabLinks; let i = index"
77
[routerLink]="tabLink.link"
8-
[active]="activeLinkIndex === i"
9-
(click)="activeLinkIndex = i">
8+
routerLinkActive #rla="routerLinkActive"
9+
[active]="rla.isActive">
1010
{{tabLink.label}}
1111
</a>
1212
</nav>

src/demo-app/tabs/tabs-demo.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {Component, ViewEncapsulation} from '@angular/core';
2-
import {Router} from '@angular/router';
32
import {Observable} from 'rxjs/Observable';
43

54
@Component({
@@ -16,7 +15,6 @@ export class TabsDemo {
1615
{label: 'Rain', link: 'rainy-tab'},
1716
{label: 'Fog', link: 'foggy-tab'},
1817
];
19-
activeLinkIndex = 0;
2018

2119
// Standard tabs demo
2220
tabs = [
@@ -62,18 +60,12 @@ export class TabsDemo {
6260

6361
asyncTabs: Observable<any>;
6462

65-
constructor(private router: Router) {
63+
constructor() {
6664
this.asyncTabs = Observable.create((observer: any) => {
6765
setTimeout(() => {
6866
observer.next(this.tabs);
6967
}, 1000);
7068
});
71-
72-
// Initialize the index by checking if a tab link is contained in the url.
73-
// This is not an ideal check and can be removed if routerLink exposes if it is active.
74-
// https://github.com/angular/angular/pull/12525
75-
this.activeLinkIndex =
76-
this.tabLinks.indexOf(this.tabLinks.find(tab => router.url.indexOf(tab.link) != -1));
7769
}
7870

7971
addTab(includeExtraContent: boolean): void {

0 commit comments

Comments
 (0)