Reputation: 1
I have module which is resolve services when i load it, and have many components in this module, but i want to resolve the same services at every time i load TrainingsComponent. So the problem is if i open TrainingsComponent it will be a double query to services. Download services for module is important because data from this services used in components, and download data in TrainingsComponent is important because i want to get new data from services every time i load it. So how can i do this?
const routes: Routes = [
{
path: '',
resolve: {
setup: GamesListService, MissionsListService, TestService, EvolutionService
},
children: [
{
path: '',
component: TrainingsComponent,
resolve: {
setup: GamesListService, MissionsListService, TestService
},
},
{
path: 'mission-study',
component: MissionStudyComponent
},
{
path: 'sphere/:sphereAlias',
component: SingleSphereComponent
}
]
}
];
Upvotes: 0
Views: 151
Reputation: 2916
You should consider splitting services. Create a singleton service for the data you want to load on module and another one for the data you want every time to load the request. If you have common things there, place them in a base Class and extend it.
Another solution is not to emit the request from the service side.
Put that code inside your service:
export class ApiService {
private url = 'api/url';
constructor(private http: HttpClient) {}
load(): Observable<any> {
return this.http.get<any>(`${this.url}`); }
}
}
Instead of:
export class ApiService {
private url = 'api/url';
constructor(private http: HttpClient) {}
load(): Observable<any> {
return this.http.get<any>(`${this.url}`).pipe(...);
}
}
Upvotes: 1