角度的metrial标签没有打开出口的第一个标签

时间:2018-03-21 15:44:05

标签: angular angular-material angular5 angular-material2 angular-routing

我的路线如下所示。当用户使用URL加载应用程序时 - > http://localhost:4200/will-kit 我只获得了TABS,并且没有看到默认加载的第一个标签

enter image description here

点击开始标签后,标签会打开,网址将为 - > http://localhost:4200/will-kit/(taboutlet:./start)

enter image description here

const routes: Routes = [   { path: 'will-kit', component: WillKitLayoutComponent, children: [
    {
        path: '',
        redirectTo: './start',
        pathMatch: 'full'
    },
    {
        path: './start',
        component: StartComponent,
        outlet: 'taboutlet'
    },
    {
        path: './you',
        component: YouComponent,
        outlet: 'taboutlet'
    },
    {
        path: './status',
        component: StatusComponent,
        outlet: 'taboutlet'
    } ]} ];

以HTML格式标记代码

 <nav mat-tab-nav-bar>
            <a mat-tab-link class="mat-test" *ngFor="let routeLink of routeLinks; let i = index;" [routerLink]="[{outlets: {taboutlet: routeLink.link}}]"
              routerLinkActive #rla="routerLinkActive" 
(click)="activeLinkIndex = i" [active]="rla.isActive" [routerLinkActiveOptions]="{exact: true}">
      <label class="mat-subheading-1">{{routeLink.label}} </label>
            </a>

          </nav>

2 个答案:

答案 0 :(得分:1)

您可以使用AfterViewInit功能默认打开第一个标签

答案 1 :(得分:0)

按照建议在AfterViewInit中处理路线,这是默认加载第一个标签

 public ngAfterViewInit() {

        this.router.navigate([{ outlets: { 'taboutlet': './start' } }], {
            relativeTo: this.route
        });
    }