Welcome tag moderator AKA Unofficial DEV cheerleader. While most of my friends are found on SnapChat or Tic-Toc, you can find me here. And I OOP, but I’m not a VSCO girl.
Welcome tag moderator AKA Unofficial DEV cheerleader. While most of my friends are found on SnapChat or Tic-Toc, you can find me here. And I OOP, but I’m not a VSCO girl.
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;
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:blockHow 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.