I want to get some data from the resolver after I do some filtering with the data I get from the backend. Everything works fine with getting the data from the backend and filtering it, but the problem is that I cannot return the final data so I can get it into the component, Please see below my code:
Resolver:
resolve = (route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> => {
let routeObjKeys = Object.keys(route.params);
let jobApplicationsArray = [];
if(routeObjKeys.length !== 0) {
let response = this.jobApplicationsService.getJobApplications('', 0, 100, 'firstName', 'ASC').subscribe(data => {
routeObjKeys.forEach(function(key) {
jobApplicationsArray.push(data["data"].filter(jobApp => jobApp.id === route.params[key])[0]);
});
console.log("jobApplicationsArray: ", jobApplicationsArray);
return jobApplicationsArray;
});
return Observable.of(response);
} else {
return this.jobApplicationsService.getJobApplications('', 0, 10, 'firstName', 'ASC');
}
}
Component:
getResolverData = () => {
this.route.data.subscribe(data => { // Get the data from the resolver
console.log('jobApplications from component: ', data);
});
}
Into the resolver, the jobApplicationsArray
array contains the filtered data, but in the component it is undefined, so I think I don't return it properly from the resolver. Please advise. Thanks!