Monday, January 8, 2018

Angular–Prevent a user from navigating away when there are unsaved changes

Here is a quick code snippet that I got from a collegae on how to prevent a user from navigating away from a page.

In our situation we want to avoid that a user forgets to save his changes and therefore want to show an explicit warning. This is not that hard to to in Angular thanks to the availability of the @HostListener decorator:

No comments: