5.1: Dropdown Functionality
Last updated
Last updated
Right now, our dropdown isn't working and we're simply logging the user out when a clicking on their welcome message. Let's fix that!
We'll use the ngx-bootstrap library that we added to our project earlier. if you'd like to learn more or customize it.
In your app.module.ts
file - import the BsDropdownModule
and add it to the imports array:
In nav.component.html, update the div containing the dropdown to the following:
We'll also update the nav.component.scss
file to make the cursor a pointer when hovered over the element:
Right now, when our users login - they stay at the home page. But, it would be better if we directed them to the list of users.
In nav.component.ts
, inject Router into the component:
Next, modify the login()
method to redirect after completion:
Open the browser and verify that you are being redirected when you login.
Similarly, we'll redirect the user after logging out to the home page
Update the logout()
method in nav.component.ts: