Loading data with resolve guard
A resolve guard is a different kind of router guard, as mentioned in Chapter 6, Implementing Role-Based Navigation. A resolve guard can load necessary data for a component by reading record IDs from route
parameters, asynchronously loading the data, and having it ready when the component activates and initializes.
The major advantages of a resolve guard include reusability of the loading logic, a reduction of boilerplate code, and the shedding of dependencies because the component can receive the data it needs without having to import any service:
- Create a new
user.resolve.ts
class underuser/user
:src/app/user/user/user.resolve.ts import { inject } from '@angular/core' import { ActivatedRouteSnapshot, ResolveFn } from '@angular/router' import { catchError, map } from 'rxjs/operators' import { transformError } from '../../common/common' import { User } from './user' import { UserService...