How to hide Login on Menu once a user is already logged in
For further actions, you may consider blocking this person and/or reporting abuse
How to hide Login on Menu once a user is already logged in
For further actions, you may consider blocking this person and/or reporting abuse
Lem Dulfo -
Mohin Sheikh -
Ahmed Jaad -
Thomas B. -
Top comments (9)
I need to hide the login button based on login
Don't forget to show the button again when the user logs out
Ok do you know how to implement this?
For the same div that you did a
display:none
, do adisplay:block
How can i implement that
I need to hide the login button in navigation menu when user is loggedin
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
π
Some comments may only be visible to logged-in visitors. Sign in to view all comments.