I am trying to write a DataResolver service that will allow an Angular 2 router to preload data before initializing my component.
The solver needs to call different API endpoints to retrieve the data corresponding to the loaded route. Instead of having a resolver for each of my many components, I create one common resolver. Thus, I would like to pass user input in a route definition that points to the correct endpoint. For example, consider these routes:
app.routes.ts
appRoutes = [ { path: 'project/:id', component: ProjectComponent, resolve: { data: DataResolver } }, { path: 'store/:id', component: StoreComponent, resolve: { data: DataResolver } } ]
In the first case, the resolver needs to call /path/to/resource1/id . In the second case, /path/to/resource2/id . Ideally, I would pass the endpoint as an argument in the definition of the route, which will then be available in the DataResolver constructor.
Is it possible to do this using a common recognizer class?
Angular 2.0.1 recorded in Typescript 2.0.3
source share