I have a request regarding certain elements that are to be displayed on all pages except the login page. I am considering using either ngIf or the hidden property of the elements to hide them when the user is on the login page.
Here is what I have attempted:
<div [hidden]="router.isRouteActive(router.generate('/login'))">
This method was suggested in response to a similar question found here: In Angular 2 how do you determine the active route?
In addition, I also tried:
<div *ngIf="!router.isRouteActive(router.generate('/login'))">
Unfortunately, neither attempt has been successful so far.
For further context, below is the component corresponding to this HTML code.
import { Component, OnInit } from 'node_modules/@angular/core';
import { HTTP_PROVIDERS, XHRBackend } from 'node_modules/@angular/http';
import { Routes, Router, ROUTER_DIRECTIVES } from 'node_modules/@angular/router';
import { LoginService } from './login/login.service';
import { LoginComponent } from './login/login.component';
import { UserComponent } from './user/user.component';
@Component({
selector: 'portal',
templateUrl: 'portal/portal.component.html',
directives: [ROUTER_DIRECTIVES, LoginComponent, UserComponent ],
providers: [
HTTP_PROVIDERS,
LoginService
]
})
@Routes([
{ path: '/login', component: LoginComponent},
{ path: '/user/:username', component: UserComponent}
])
export class PortalComponent implements OnInit{
private router: Router
constructor() {}
ngOnInit() {
this.router.navigate(['/login']);
}
}
The information available on isRouteActive and generate methods is limited. Can someone provide guidance on a more effective approach to achieve this functionality?