私はリゾルバを書いたコンポーネントを持っています。Angular2 - ルートの複数のリゾルバー(順番に1つ)を持つ方法
- まず、すべてのアクティブな国を取得 -
は、ここで私はリゾルバに何をしたいのです。
- これらの国の州を取得します(私は選択された国のIDを取得します)。 国を取得するためのURLがある - - 私はRESTfulなAPIを書かれているサーバーで
http://localhost:3000/api/v1/country/search?query={%22isActive%22:true}
国の状態を取得するためのURLがある - ここhttp://localhost:3000/api/v1/country/1/state/search?query={%22isActive%22:true}
は、私が持っている方法ですそれのための決議を書いた -
一般設定 - 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
}
}
})
});
}
}
一般settings.component.ts
this.route.data.subscribe((data : {everything: any}) => {
console.log(data) //<---- Here data.everything is printed as undefined.
})
一般設定-routing.module.ts私は私が行うことができます知っている
let generalSettingsRoutes: Routes = [
{
path: '',
component: GeneralSettingsComponent,
data: {
pageTitle: 'Organization Settings'
},
resolve: {
everything: GeneralSettingsResolverService,
}
}];
これは複数のresolve
を使用しています。しかし、私はこれを1つの方法で行うことができます。データを1つずつ取得します。
これまでのところ、まだまだ!ありがとう。 – mridula