I
I
iluxa18102019-05-14 23:59:09
Angular
iluxa1810, 2019-05-14 23:59:09

Why is the method called before the end of resolve and so many times?

There is such a resolve:

export class PermissionResolver implements Resolve<any> {
     constructor(private authService: AuthorizationService, private permissionService: PermissionService) { }

     resolve(
          route: ActivatedRouteSnapshot,
          state: RouterStateSnapshot
     ): Observable<any> | Promise<any> | any {
          return this.authService.authorize().pipe(tap(() => {
               this.permissionService.currentUser = this.authService.currentUser;
          }));
     }
}

Hooked to the route like so:
const appRoutes: Routes = [
  {
    path: '', component: HomeComponent, pathMatch: 'full', resolve: { data: PermissionResolver }
  }
];

So the following worries me:
1) When a breakpoint is left here this.permissionService.currentUser=this.authService.currentUser, the console is already full of errors about undefined, since currentUser is used in the binding and the site menu is also displayed.
If you believe the documentation, then the page should not be loaded until resolve.
2) This service is bound in the component:
<li class="nav-item"><a class="nav-link" [ngClass]="{'disabled':!permissionService.canView()}"

, as I said, the console is full of errors. And when the errors pass, then 10 messages about the successful method call are displayed in the console (I log this method).
HomeComponent is:
<body>
<nav-menu></nav-menu>
<router-outlet></router-outlet>
</body>

It is in the nav-menu that I call the accessibility methods.
I climbed all over the code and I use it this method only in this one place ...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question