Skip to content

refactor(tabs-demo): replace active link index #4729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/demo-app/tabs/tabs-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ <h1>Tab Nav Bar</h1>
<a md-tab-link
*ngFor="let tabLink of tabLinks; let i = index"
[routerLink]="tabLink.link"
[active]="activeLinkIndex === i"
(click)="activeLinkIndex = i">
routerLinkActive #rla="routerLinkActive"
[active]="rla.isActive">
{{tabLink.label}}
</a>
</nav>
Expand Down
10 changes: 1 addition & 9 deletions src/demo-app/tabs/tabs-demo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Component, ViewEncapsulation} from '@angular/core';
import {Router} from '@angular/router';
import {Observable} from 'rxjs/Observable';

@Component({
Expand All @@ -16,7 +15,6 @@ export class TabsDemo {
{label: 'Rain', link: 'rainy-tab'},
{label: 'Fog', link: 'foggy-tab'},
];
activeLinkIndex = 0;

// Standard tabs demo
tabs = [
Expand Down Expand Up @@ -62,18 +60,12 @@ export class TabsDemo {

asyncTabs: Observable<any>;

constructor(private router: Router) {
constructor() {
this.asyncTabs = Observable.create((observer: any) => {
setTimeout(() => {
observer.next(this.tabs);
}, 1000);
});

// Initialize the index by checking if a tab link is contained in the url.
// This is not an ideal check and can be removed if routerLink exposes if it is active.
// https://github.com/angular/angular/pull/12525
this.activeLinkIndex =
this.tabLinks.indexOf(this.tabLinks.find(tab => router.url.indexOf(tab.link) != -1));
}

addTab(includeExtraContent: boolean): void {
Expand Down