I am very new to Angular, and was unsuccessful in finding an answer to what I am searching for.
The problem I am facing right now is that all the global error messages are not disappearing when I switch to another route.
I tried to solve this problem by using the CanDeactivate interface. This is my canDeactivate method:
canDeactivate(): Observable<boolean> {
console.log('delete test');
this.globalMessageService.remove(GlobalMessageType.MSG_TYPE_ERROR);
return of(true);
}
This method is created in a Service called cms-page.guard.ts and by using this in specific pages, it seems to work just fine. Example if I use this in the "Courses" page:
const routes: Routes = [
{
path: 'courses',
canActivate: [CmsPageGuards],
canDeactivate: [CmsPageGuards],
data: { pageLabel: 'courses' },
component: CoursesPageComponent
}
];
Basically, what I did is apply the canDeactivate method on a specific page. I was wondering if it is possible to create a Guard that applies globally the canDeactivate method, so it works for all pages when you change to another route?