March 2017
Intermediate to advanced
118 pages
2h 1m
English
After the router has run the guards, it will resolve the data. To see how it works, let's tweak our configuration from above:
[
{
path: ':folder',
children: [
{
path: '',
component: ConversationsCmp,
resolve: {
conversations: ConversationsResolver
}
}
]
}
]
Where ConversationsResolver is defined as follows:
@Injectable()
class ConversationsResolver implements Resolve<any> {
constructor(private repo: ConversationsRepo, private currentUser: User) {}
resolve(route: ActivatedRouteSnapshot, state: RouteStateSnapshot):
Promise<Conversation[]> {
return this.repo.fetchAll(route.params['folder'], this.currentUser);
}
}
Finally, we need to register ConversationsResolver when bootstrapping our application:
@NgModule({ //... providers: [ConversationsResolver], ...Read now
Unlock full access