我有一个页面,其中有三个按钮,管理员,学生和注销。退出按钮必须仅在路径更改为/admin
or后出现/student
,并使管理员和学生按钮消失。如何在这个问题中使用 routerActiveLink?
主页.html:
<mat-toolbar color="primary">
<span class="align-content">Online Library Portal</span>
<button mat-button routerLink="/adminLogin" routerLinkActive="active" (click)="showPage()">Admin</button>
<button mat-button routerLink="/studentLogin" routerLinkActive="active" (click)="showPage()">Student</button>
<button mat-button routerLink="/adminLogin" [routerLinkActive]="['admin']" *ngIf="logout">Logout</button>
</mat-toolbar>
<mat-card-content *ngIf="show">
<div class="welcome">
<h1>Welcome to Anitha's Library</h1>
</div> <div class="instructions">
<li>
If you are an <strong>Admin</strong>, please choose admin option to Login or Register.
</li>
<li>
If you are a <strong>Student</strong>, please choose student option to Login or Register.
</li>
</div>
</mat-card-content>
home.component.ts:
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor(private router: Router) {}
show: boolean = true;
logout: boolean = true;
ngOnInit() {
this.router.navigate([''])
}
showPage() {
this.show = false;
}
if([routerLinkActive]="['admin']"){
this.logout=false;
}
}
我是角度的新手。我是否正确使用了它?