1
是否有可能在angular2中的主要組件之前解析服務?主(自舉)組件的Angular2解析器?
是否有可能在angular2中的主要組件之前解析服務?主(自舉)組件的Angular2解析器?
執行的決心服務下的應用程序的默認
export const appRoutes: Routes = [
{path:'', pathMatch: 'full', redirectTo: 'home'},
{
path: 'home',
component: AppComponent,
resolve: function(){
//your service call
},
{
path: 'path1/:id',
component: YourComponent,
resolve: {
someObject: ComponentResolve
}
}
];
@Injectable()
export class ComponentResolve implements Resolve<Interface> {
constructor(private yourService: YourService) {}
resolve(route: ActivatedRouteSnapshot) {
return this.yourService.getMethod(route.params['id']);
}
那裏是我的自舉主要成分的路由,'路徑:「」'重定向到'道:「家」,成分:「HomeComponent'' ,AppComponent由'@NgModule({..... bootstrap:[AppComponent]'})'引導'' –
你的應用程序的入口點是什麼? – Aravind
我使用'platformBrowserDynamic()。bootstrapModule(AppModule);' –