DEV Community

Discussion on: Login Menu hide

Collapse
 
ankit199 profile image
Ankit kumar shukla

1) Add this to your service provider:-

import { Subject } from 'rxjs/Subject';

public isLogged= new Subject();
setIslogged(value: boolean) {
this.isLogged.next(value); //it is publishing this value to all the subscribers that have already subscribed to this message
}

2) For Login Page ****

import your service for the login page

inside your login method after subscription/successfully login publish is logged variable

this.yourservice.setIslogged(true);

and in your logout method

this.yourservice.setIslogged(false);

3) In Your NavBar Component
import your service for the NavBar Component
declare variable
isLogin:any;

ngOnInit() {
this.yourservice.isLogged.subscribe(
(isLoggeduser) => {
this.isLogin= isLoggeduser;
}
);
}

add a condition with *ngIf="isLogin" in your login button

Collapse
 
dreamcatcher8055 profile image
Akhil Ashok

👍