Reference: How can I detect service variable change when updated from another component?
Current Behavior: Users login and the menu items does not update when variable values changes in the header component. It only updates when the page is refreshed.
Expected Behavior: Hide menu some of the menu items when user logs in - immediately.
Header component contains menu and subscribed to authentication service:
isAuthenticated: boolean = false;
this.items = [
{
title: 'Home',
link: '/',
home: true,
},
{
title: 'Dashboard',
link: '/dashboard',
hidden: !this.isAuthenticated,
},
]
ngOnInit() {
this.authService.isAuthenticated().subscribe(res => this.isAuthenticated = res);
}