下面的代码取自material.angular.io:
<nav mat-tab-nav-bar>
<a mat-tab-link
*ngFor="let link of navLinks"
[routerLink]="link.path"
routerLinkActive #rla="routerLinkActive"
[active]="rla.isActive">
{{link.label}}
</a>
</nav>
<router-outlet></router-outlet>
零件:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
navLinks = [
{label: 'Home', path: 'home'},
{label: 'Contacts', path: 'contacts'},
{label: 'Settings', path: 'settings'}
];
}
当我尝试运行此示例时,导航需要单击主页才能打开组件。我希望最初显示 home 的内容。您如何将第一个值设置为默认活动选项卡?