I'm trying to implement a global dirty checker in Angular. We have a solution that requires configuring each component, but I was hoping to generalize it more.
I wired up global code that would check each active component and then signal whether or not the user should be prompted. Or at least, I thought it was doing that. My initial plan was listing to router.events
for NavigationEnd
events and inspecting the current ActivatedRoute
because it exposes a component
property. However, that property is the type/class of the component and not the actual instance.
I have yet to find an API that exposes the current component instances. Does it exist or am I stuck?
UPDATE
The usecase I am struggling with is not route changes, but when the window closes. When window:beforeunload
fires, I don't have any way to ask the component instances if they are dirty.
UPDATE 2 Created issue: https://github.com/angular/angular/issues/18634