Q:

Angular2 - How to have multiple Resolvers (one after the other) for a route

I have a component, for which I have written a resolver. 
Here's what I want to do in the resolver - 

First get all active countries.
Then get the states of one of those countries (I will have the ID of the country that is selected).

On the server I have written RESTful APIs - 
The URL for getting the countries is - http://localhost:3000/api/v1/country/search?query={%22isActive%22:true}
The URL for getting the states of a country is -
http://localhost:3000/api/v1/country/1/state/search?query={%22isActive%22:true}
Here's how I have written the resolver for it - 
general-settings-resolver.service.ts
@Injectable()
export class GeneralSettingsResolverService implements Resolve<any> {
constructor(private service: GeneralSettingsService) { }
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<any> {
    return this.service.getAllActiveCountries().then(countries => {
        this.service.getActiveStatesOfCountry(7).then(states => {
            return {
                everything: {
                    countries: countries,
                    states: states
                }
            }
        })
    });
}

}
general-settings.component.ts 
this.route.data.subscribe((data : {everything: any}) => {
        console.log(data) //<---- Here data.everything is printed as undefined.

    })

general-settings-routing.module.ts
let generalSettingsRoutes: Routes = [
{
    path: '',
    component: GeneralSettingsComponent,
    data: {
        pageTitle: 'Organization Settings'
    },
    resolve: {
        everything: GeneralSettingsResolverService,
    }
}];

I know I can do this using multiple resolves. But can I do this using a single one, in which I get data one after the other.

A:

I don't know much about the route resolvers, but I think you are missing a return statement in the general-settings-resolver.service.ts. It should probably be like:
return this.service.getActiveStatesOfCountry(7).then(...)

or just remove the curly braces from around that call. Otherwise your "everything" object gets just lost in a void :-)

