Hi,
I am trying to find out why my nav bar is acting weird!
I have links for login, logout and register. everything is working fine exept for the navbar.
I am getting the content of a logged-in user at the start of the program and I am not getting the buttons for login and register!
nav bar code for the buttons:
<div>
<ul class="nav navbar-nav" style="margin-right: 75px;">
<li *ngIf="!loggedin()" class="nav-item">
<a class="nav-link"
routerLink="user/register"
routerLinkActive="active"
>Register</a>
</li>
<li *ngIf="!loggedin()" class="nav-item">
<a class="nav-link"
routerLink="user/login"
routerLinkActive="active"
>Login</a>
</li>
<div *ngIf="loggedin()" class="dropdown" dropdown>
<a herf="#" class="dropdown-toggle text-light" dropdownToggle (click)="false">
Welcome {{ loggedinUser }}
</a>
<div class="dropdown-menu" *dropdownMenu>
<a href="/" class="dropdown-item">
<i class="fas fa-tachometer-alt"></i>View Dashboard</a>
<a href="/" class="dropdown-item">
<i class="far fa-user-circle"></i>My Profile</a>
<a href="/" class="dropdown-item">
<i class="fas fa-key"></i>Change Password</a>
<a (click)="onlogout()" class="dropdown-item">
<i class="fas fa-sign-out-alt"></i>Logout</a>
</div>
</div>
</ul>
</div>
and code for the functions loggedin and onlogout:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-nav-bar',
templateUrl: './nav-bar.component.html',
styleUrls: ['./nav-bar.component.css']
})
export class NavBarComponent implements OnInit {
loggedinUser: string;
constructor() { }
ngOnInit() {}
loggedin()
{
this.loggedinUser = (localStorage.getItem('token') || '{}');
return this.loggedinUser;
}
onlogout()
{
localStorage.removeItem('token');
}
}