Reacting to Domain Events

Learn how to react to domain events in Angular and update the user interface accordingly by subscribing to the events and handling them in the relevant components.

Our Angular application is almost complete. There are a few things that we still need to do in order to round it out.

  • Firstly, once a user has completed the login form, we should close the login sidebar and show the main content once again.

  • Secondly, we should update the user-details component to show the currently logged-in username, as well as hide the “login” button. These changes can all occur on the back of the domain event USER_LOGIN_EVENT. To hide the sidebar, we need to react to the USER_LOGIN_EVENT within the app component, as it is in charge of showing and hiding the sidebar.

Closing the login sidebar and showing the main content

This can easily be accomplished by updating the app.component.ts file as follows:

Get hands-on with 1400+ tech skills courses.