2016-11-29 108 views
1

我必须开发一个角度2应用程序,它是其他角度2应用程序的包装。Angular 2包装项目

可以说,项目的主要模块称为MainModule其部署在NPM 其他第三方模块AppModule1,AppModule2,... 我可以将其与安装到我的主要项目“NPM我appmodule1”等。

这里是我的代码:

import {AppModule1} from 'ThirdPartyLibrary/AppModule1'; 
import {AppModule2} from 'ThirdPartyLibrary/AppModule2'; 
import {AppModule3} from 'ThirdPartyLibrary/AppModule3'; 

(模块的进口休息太) ..(可以说我做了这个动态)

@NgModule({ 
imports: [ 
    BrowserModule, 
    HttpModule, 
    FormsModule, 
    RouterModule.forRoot(routes), 
    AppModule1,AppModule2,..(lets say I made this dynamic) 
], 
declarations: [ 
    MainComponent 
], 
schemas: [ CUSTOM_ELEMENTS_SCHEMA ], 
providers: [ 
    AnyMainModuleService, 
    {provide: LocationStrategy, useClass: HashLocationStrategy} 
], 
bootstrap: [ MainComponent ] 

}) 出口类MainModule {}

AppModule1,2,3 ..具有进口阵列中其RouterModule.forChild(路由)。我也尝试使用RouterModule.forRoot(路由)。

路由器配置:

{ path: '', redirectTo: 'AppComponent1' }, 
{ path: 'appcomponent1', component: AppComponent1 }, 
{ path: 'appcomponent2', component: AppComponent2 }, 
{ path: 'appcomponent3', component: AppComponent3 }, 
{ path: 'appcomponent4', component: AppComponent4, children: childRoutesOfAppModule4enter code here }, 

内部AppModule4路由器配置

export const routes: Routes = [ 
     { path: '', redirectTo: 'home'}, 
     { path: 'home', component: HomeComponent }, 
     { path: 'about', component: AboutComponent} 
    ]; 

的问题是,其被认为是主要组件的子路由AppModule4的路由器配置过骑着主路由器。

只要我进入本地主机我有看到AppComponent1但我得到HomeComponent。

回答

0
{ path: 'appcomponent4', component: AppComponent4, loadChildren:() => AppModule4} 

使用这种导入路由器模块和AppModule4内安装路径为RouterModule.forChild(路由)