I have a navbar component, inside its ngOnInit
function I have checked if user is logged in or not, if the user is logged in then I change isAuthorized
to true, and its default is false
, then I check with *ngIf="isAuthorized"
, in my menu li
s.
Now when the user is not logged in some of my menu items are not created, and when the user clicked on the post like button, I have checked to show login modal if the user is not logged in. After user logged in, I can change isAuthorized
of navbarComponent
from false
to true
, but my navbar component can't detect the changes and create other menus.
Inside login function I have:
this.navbar.refresh();
after I have set token, and inside navbar component, I have a refresh function:
refresh() {
this.isAuthorized = true;
this.changeDetector.detach();
setInterval(() => {
this.changeDetector.reattach();
// if (!this.changeDetector['destroyed']) {
this.changeDetector.detectChanges();
// }
this.changeDetector.detach();
}, 10000);
}
The main thing I want is to prevent from reloading when a user logged in with modal, and show other menu items.