From the course: Building Angular and ASP.NET Web API Apps

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Update the header for logout functionality

Update the header for logout functionality

From the course: Building Angular and ASP.NET Web API Apps

Update the header for logout functionality

- [Instructor] In this part you learn how to dynamically update the header here at the top right based on the user status. So if the user is logged in, then we want to show the add transaction and the logout button, and if the user is logged out, then we want to show the login button. For that we need to first update the authentication service and here at the top I'm going to use a behavior subject to manage the current user state. This allows us to track whether a user is logged in or not and just share the state across different parts of the app. We're going to just define that here at the top. So just after the private api endpoint, I'm going to type private currentUserSubject = new BehaviorSubject. So this way we can basically track user state and then just share this state across different parts of the app. So BehaviorSubject, this is going to be string or null. The default value is going to be null. And then we're going to use this currentUser, which is an observable, and this…

Contents