This website collects cookies to deliver better user experience
How to display a navbar component after logging in without reloading the page in angular 12
How to display a navbar component after logging in without reloading the page in angular 12
My landing page does not show a navbar, but I want to display a navbar after logging in successfully. Currently, I'm able to show navbar if I do a full page reload after logging in successfully. I'm very sure that there is a better way than this approach.
login(){this.credentials=this.myForm.value;if(this.credentials){this.loginService.authenticate(this.credentials).subscribe(data=>{this.storageService.setLocalStorageItem('auth',JSON.stringify(data));this.dataService.global.showNav=true;this.sharedService.getProjectMetadata().subscribe(metadata=>{this.storageService.setLocalStorageItem('projectMetaData',JSON.stringify(metadata));this.router.navigate(['/home']);})},err=>console.log(err));}else{console.log('Please enter your username and password');}}
exportclassNavbarComponentimplementsOnInit{user:IAuth={};showNavbar: boolean;progressbar: number =0;constructor(privatestorageService:StorageService,privatedataService:DataService){this.showNavbar=this.dataService.global.showNav;}ngOnInit():void{this.user=JSON.parse(this.storageService.getLocalStorageItem('auth'));if(this.user){this.showNavbar=true;}}}
Please help me out. Your help is highly appreciated. Thank you.