2017-09-01 47 views
1

我无法让我的DropSelectComponent共享组件在loadChildren Contact或Support模块中工作。它无论是急于加载还是延迟加载都不起作用。 DropSelect组件是服务模块的一部分,并在受保护的模块 - layoutcomponent中正常加载。请指教?Angular 4急切或延迟加载 - SharedModule不能正常工作

Protected.routes.ts

const protectedRoutes: Routes = [ 
     { 
     path: 'protected', 
     component: LayoutComponent, 
     canActivate: [AuthGuard], 
     children:[ 
      { path:'', redirectTo: 'contact', pathMatch:'full'}, 
      { path:'support', loadChildren:() => SupportModule}, 
      { path:'contact', loadChildren:() => ContactModule}, 
      // { path:'support', loadChildren:'./support/support.module#SupportModule'}, 
      // { path:'contact', loadChildren:'./support/contact.module#ContactModule'}, 
     ] 
     } 
    ]; 

    @NgModule({ 
     imports: [RouterModule.forRoot(protectedRoutes)], 
     exports: [RouterModule] 
    }) 
    export class ProtectedRouteModule { } 

Protected.module.ts

@NgModule({ 
    imports: [BasicModule, ServicesModule, ProtectedRouteModule], 
    exports: [], 
    schemas: [CUSTOM_ELEMENTS_SCHEMA], 
    declarations: [ 
     LayoutComponent 
     ], 
    providers: [LayoutService], 
}) 
export class ProtectedModule { } 

Support.module

import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 
import { CommonModule } from '@angular/common'; 
import { DashboardComponent } from './dashboard/dashboard.component'; 
import { DashboardCardsComponent } from './dashboard/dashboard-cards.component'; 
import { DashboardTableComponent } from './dashboard/dashboard-table.component'; 
import { SupportRouteModule } from './support.routes'; 

@NgModule({ 
    imports: [SupportRouteModule], 
    declarations: [ 
     DashboardComponent, DashboardCardsComponent, DashboardTableComponent 
    ], 
    exports: [], 
    schemas: [CUSTOM_ELEMENTS_SCHEMA], 
    providers: [], 
}) 
export class SupportModule { } 

支持的路由

const routes: Routes = [ 
    { path:'', redirectTo: 'dashboard', pathMatch:'full'}, 
    { 
    path: 'dashboard', component: DashboardComponent, children:[ 
     { path: '', component: DashboardCardsComponent}, 
     { path: 'table', component: DashboardTableComponent}, 
    ] 
    } 

]; 


@NgModule({ 
    imports: [RouterModule.forChild(routes)], 
    exports: [RouterModule] 
}) 

export class SupportRouteModule { } 

服务模块

@NgModule({ 
    imports: [CommonModule, HttpModule, FormsModule, RouterModule, MyDatePickerModule], 
    declarations: [LoaderComponent, PagerComponent, FullScreenDirective, DashPipe, CutPipe, SearchPipe, DropSelectComponent], 
    exports: [CommonModule, HttpModule, FormsModule, RouterModule, LoaderComponent, PagerComponent, DashPipe, CutPipe, SearchPipe, DropSelectComponent], 
    providers: [LoaderService, SessionStorage, LocalStorage, ClockService, StorageService, 
      { 
      provide: HttpService, 
      useFactory: HttpServiceFactory, 
      deps: [XHRBackend, RequestOptions, Router, LoaderService, StorageService] 
      }, 
    ], 
    schemas: [CUSTOM_ELEMENTS_SCHEMA], 
}) 
export class ServicesModule { } 
+0

哪里是你的共享模块可以为您发布 –

+0

ServicesModule是一个我想与ProtectedModule和SupportModule –

回答

0

你有没有在你的support.module其导入。做到这一点,它应该工作:

@NgModule({ 
    imports: [SupportRouteModule, ServicesModule], // Here 
    declarations: [ ... ], 
    exports: [], 
    schemas: [CUSTOM_ELEMENTS_SCHEMA], 
    providers: [], 
}) 
export class SupportModule { } 
+0

没错共享跨越,得益于它的工作原理,当我导入ServicesModule做预先加载在ProtectedRouteModule中,但不是在懒惰加载时... –

+0

我现在正面临 - 遇到错误时遇到静态解析符号值。引用本地(非导出)符号'protectedRoutes'。考虑导出符号(原始.ts文件中的位置9:7),解析/protected/protected.routes.ts中的符号ProtectedRouteModule –