Problem Statement
What is a Resolver and why is it useful?
Explanation
A Resolver fetches data before a route activates so the component receives ready-to-use data and you avoid blank states or flickers. If the resolver fails, you can redirect or show an error route.
Code Solution
SolutionRead Only
export class UserResolver implements Resolve<User> {
constructor(private api: Api) {}
resolve(): Observable<User> { return this.api.getUser(); }
}
// route: { path:'profile', component:ProfileCmp, resolve:{ user:UserResolver } }Practice Sets
This question appears in the following practice sets: