Angular Material 2选项卡链接无法设置默认活动选项卡

时间:2017-09-13 20:13:45

标签: angular angular-material2 routerlink routerlinkactive angular2-md-tabs

在登录页面成功登录后,路线将更改为“入站”视图,该视图在导航栏中有两个选项卡,“入站”和“出站”。我想选择“入站”导航框来反映路由器的状态。但是,在实施this演示后,默认情况下仍未选中

html:

        <nav md-tab-nav-bar *ngIf="!router.url.includes('login')">
            <a md-tab-link 
               *ngFor="let tabLink of tabLinks; let i = index"
               [routerLink]="tabLink.link"
               routerLinkActive #rla="routerLinkActive"
               [active]="rla.isActive">
                {{tabLink.label}}
            </a>
        </nav>

成分:

import { Component }            from '@angular/core';
import { Router }               from '@angular/router';
import { MdTab, MdTabLink }     from '@angular/material';

@Component({
    selector: 'header',
    templateUrl: './header.component.html',
    styleUrls: [ './header.component.css' ]
})

export class HeaderComponent {     
    tabLinks = [
        { label: 'Inbound', link: 'inbound' },
        { label: 'Outbound', link: 'outbound' }
    ];
    constructor( private router: Router ) { }
}

路线:

    const appRoutes: Routes = [
    {
        path: '',
        redirectTo: '/inbound',
        pathMatch: 'full'
    },
    {
        path: 'inbound',
        component: InboundMessagesComponent,
        canActivate: [ RouteGuard ]
    },
    {
        path: 'outbound',
        component: OutboundMessagesComponent,
        canActivate: [ RouteGuard ]
    },
    {
        path: 'login',
        component: LoginComponent
    }
];

0 个答案:

没有答案