我尝试让延迟加载工作。但是当我删除de模块时,谁负责app.module中的延迟加载。该应用程序不再起作用。
谷歌搜索很多。更改代码
所以我有一个dossier.module.ts,像这样:
imports: [
RouterModule,
CommonModule,
ReactiveFormsModule,
DossierRoutingModule,
PdfViewerModule,
SharedModule
],
declarations: [
DossierComponent,
DossierCorrespondenceComponent,
DossierCorrespondenceItemComponent,
DossierEntryComponent,
DossierEntrySummaryComponent,
DossierHistoryComponent,
DossierLabComponent,
DossierMedicationComponent,
DossierMiscComponent,
DossierPhysicalComponent,
DossierPdfComponent,
PdfViewerComponent,
BrochureDetailComponent,
TopbarComponent
],
我有一个DossierRoutingModule:
const dossierRoutes = [
{
path: '',
component: DossierComponent,
canActivate: [AuthGuard],
children: [
{path: '', redirectTo: 'voorgeschiedenis', pathMatch: 'full', CanActivate: [AuthGuard] },
{path: 'voorgeschiedenis', component: DossierHistoryComponent, CanActivate: [AuthGuard] },
{path: 'lichamelijk', component: DossierPhysicalComponent, CanActivate: [AuthGuard] },
{path: 'lab', component: DossierLabComponent, CanActivate: [AuthGuard] },
{path: 'overig', component: DossierMiscComponent, CanActivate: [AuthGuard] },
{path: 'medicatie', component: DossierMedicationComponent, CanActivate: [AuthGuard] },
{path: 'correspondentie', component: DossierCorrespondenceComponent, CanActivate: [AuthGuard] },
]
},
];
,在app.module.ts中,我删除了dossierModule。但我仍然收到此错误:
compiler.js:215 Uncaught Error: Template parse errors:
Can't bind to 'pdfTitle' since it isn't a known property of 'app-pdf-viewer'.
1. If 'app-pdf-viewer' is an Angular component and it has 'pdfTitle' input, then verify that it is part of this module.
2. If 'app-pdf-viewer' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("cklink]="{url: '/informatie', label: 'Terug'}"></app-topbar>
<app-pdf-viewer [hidden]="!pdfLoaded" [ERROR ->][pdfTitle]="brochureName" (back)="handlePdfBack()" >
</app-pdf-viewer>
"): ng:///AppModule/BrochureDetailComponent.html@1:38
'app-pdf-viewer' is not a known element:
1. If 'app-pdf-viewer' is an Angular component, then verify that it is part of this module.
2. If 'app-pdf-viewer' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("<app-topbar [backlink]="{url: '/informatie', label: 'Terug'}"></app-topbar>
[ERROR ->]<app-pdf-viewer [hidden]="!pdfLoaded" [pdfTitle]="brochureName" (back)="handlePdfBack()" >
</app-pdf"): ng:///AppModule/BrochureDetailComponent.html@1:0
at syntaxError (compiler.js:215)
at TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:14702)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:22709)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:22696)
at compiler.js:22639
at Set.forEach (<anonymous>)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:22639)
at compiler.js:22549
at Object.then (compiler.js:206)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:22548)
但这怎么可能?因为我在de dossier.module.ts中包含了PdfViewerComponent。
那该如何解决呢?
谢谢
在app.routes.ts文件中,我有这个:
{path: '', redirectTo: '/dossier', pathMatch: 'full'},
{path: 'dossier', loadChildren: './dossier/dossier.module#DossierModule' },
以及app.module.ts的导入现在看起来像这样:
imports: [
AdviceModule,
TrainingModule,
MeasurementModule,
SettingsAccountModule,
ObjectiveModule,
TodoModule,
PanelModule,
EcheqModule,
SharedModule,
BrowserModule,
FormsModule,
BrowserAnimationsModule,
AppRoutingModule,
DragulaModule.forRoot(),
RouterModule,
ChartsModule,
HttpClientModule
],
哦,这是个洞:dossier.module.ts:
@NgModule({
imports: [
RouterModule,
CommonModule,
ReactiveFormsModule,
DossierRoutingModule,
PdfViewerModule,
SharedModule
],
declarations: [
DossierComponent,
DossierCorrespondenceComponent,
DossierCorrespondenceItemComponent,
DossierEntryComponent,
DossierEntrySummaryComponent,
DossierHistoryComponent,
DossierLabComponent,
DossierMedicationComponent,
DossierMiscComponent,
DossierPhysicalComponent,
DossierPdfComponent,
PdfViewerComponent,
BrochureDetailComponent,
TopbarComponent
],
exports: [
DossierComponent,
DossierCorrespondenceComponent,
DossierCorrespondenceItemComponent,
DossierEntryComponent,
DossierEntrySummaryComponent,
DossierHistoryComponent,
DossierLabComponent,
DossierMedicationComponent,
DossierMiscComponent,
DossierNavigationComponent,
DossierPhysicalComponent,
DossierPdfComponent,
PdfViewerComponent,
BrochureDetailComponent,
//PdfViewerControlsComponent,
TopbarComponent
],
})
export class DossierModule {}
我的app.routes.ts文件如下:
const routes: Routes = [
{
path: 'auth',
component: AuthCallbackComponent
},
{
path: 'dashboard',
component: DashboardComponent,
canActivate: [AuthGuard]
},
{path: '', redirectTo: '/dossier', pathMatch: 'full'},
{path: 'dossier', loadChildren: './dossier/dossier.module#DossierModule' },
{path: 'instellingen', loadChildren: './settings/settings.account.module#SettingsAccountModule'},
{
path: 'gezondheid',
component: HealthComponent,
canActivate: [AuthGuard]
},
{
path: 'gezondheid/edit',
component: AddIndicatorComponent,
canActivate: [AuthGuard]
},
{
path: 'gezondheid/Measurement/:meting',
component: MeasurementComponent,
canActivate: [AuthGuard]
},
{
path: 'gezondheid/Lifestyle/:task',
component: TaskComponent,
canActivate: [AuthGuard]
},
{
path: 'webshop',
component: WebshopComponent,
canActivate: [AuthGuard]
},
{
path: 'selfcare',
component: SelfcareComponent,
canActivate: [AuthGuard]
},
{
path: 'advies/archief',
component: AdviceArchiveComponent,
canActivate: [AuthGuard]
},
{
path: 'informatie',
component: AdviceInformationComponent,
canActivate: [AuthGuard]
},
{
path: 'informatie/brochure/:brochure',
component: BrochureDetailComponent,
canActivate: [AuthGuard]
},
{
path: 'advies/:advies',
component: AdviceComponent,
canActivate: [AuthGuard]
},
{
path: 'advies/detail/:id',
component: AdviceDetailComponent,
canActivate: [AuthGuard]
},
{
path: 'advies',
redirectTo: 'advies/huidig',
pathMatch: 'full',
canActivate: [AuthGuard]
},
{
path: 'chat',
component: ChatFullComponent,
canActivate: [AuthGuard]
},
{
path: 'hulpbronnen',
component: ResourcePageComponent,
canActivate: [AuthGuard]
},
{
path: 'hulpbronnen/detail/:hulpbronId',
component: ResourceDetailComponent,
canActivate: [AuthGuard]
},
{
path: 'echeq',
component: EcheqOverviewComponent,
canActivate: [AuthGuard]
},
{
path: 'echeq/detail/:echeqId',
component: EcheqProcessComponent,
canActivate: [AuthGuard]
},
{
path: 'help',
component: HelpPageComponent,
canActivate: [AuthGuard]
},
{
path: 'instellingen/organisatie/:id',
component: SettingsOrganisationDetailComponent,
canActivate: [AuthGuard],
pathMatch: 'full'
},
{
path: 'trainingen',
component: TrainingComponent,
canActivate: [AuthGuard]
},
{
path: 'doel/:id',
component: ObjectiveComponent,
canActivate: [AuthGuard]
},
{
path: 'doelen',
component: ObjectiveListComponent,
canActivate: [AuthGuard]
},
{
path: 'trainingen/:training',
component: TrainingDetailComponent,
canActivate: [AuthGuard]
},
{
path: '**',
redirectTo: '/dashboard',
pathMatch: 'full'
}
];
@NgModule({
imports: [
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules})
],
exports:[RouterModule]
})
export class AppRoutingModule {}
,例如settingsRoutingModule看起来像这样:
const settingsRoutes: Routes = [
{
path: '',
component: SettingsNavigationComponent,
canActivate: [AuthGuard],
children: [
{path: '', redirectTo: 'account', pathMatch: 'full', canActivate: [AuthGuard] },
{path: 'account', component: SettingsAccountComponent, canActivate: [AuthGuard] },
{path: 'apparaten' , component: SelfcareComponent, canActivate: [AuthGuard] },
{path: 'apps' , component: SettingsAppsComponent, canActivate: [AuthGuard] },
{path: 'indicatiepermissies' , component: SettingsIndicatorPermissionsComponent, canActivate: [AuthGuard] },
{path: 'algemeen' , component: SettingsGeneralComponent, canActivate: [AuthGuard] },
{ path: 'algemeen', component: SettingsGeneralComponent, canActivate: [AuthGuard] },
{path: 'log' , component: SettingsLogComponent, canActivate: [AuthGuard] },
]
},
];
@NgModule({
imports: [RouterModule.forChild(settingsRoutes)],
exports: [RouterModule]
})
export class SettingsRoutingModule {}
但是,如果我从app.module.ts文件中删除SettingsAccountModule。应用程序中断。
例如,我在app.module.ts中执行此操作,然后应用程序Angular不再能够找到组件。
imports: [
AdviceModule,
TrainingModule,
MeasurementModule,
// SettingsAccountModule,
ObjectiveModule,
DossierModule,
TodoModule,
PanelModule,
EcheqModule,
SharedModule,
BrowserModule,
FormsModule,
BrowserAnimationsModule,
AppRoutingModule,
DragulaModule.forRoot(),
RouterModule,
ChartsModule,
HttpClientModule
],
答案 0 :(得分:1)
更新:您需要在引发错误的模块中导入发生故障的组件,还要在ng服务脚本中使用AOT
您需要在导出数组中的模块中添加可重用组件:
@NgModule({
imports: [
RouterModule,
CommonModule,
ReactiveFormsModule,
DossierRoutingModule,
PdfViewerModule,
SharedModule
],
declarations: [
DossierComponent,
DossierCorrespondenceComponent,
DossierCorrespondenceItemComponent,
DossierEntryComponent,
DossierEntrySummaryComponent,
DossierHistoryComponent,
DossierLabComponent,
DossierMedicationComponent,
DossierMiscComponent,
DossierPhysicalComponent,
DossierPdfComponent,
PdfViewerComponent,
BrochureDetailComponent,
TopbarComponent
],
exports: [
DossierComponent,
DossierCorrespondenceComponent,
DossierCorrespondenceItemComponent,
DossierEntryComponent,
DossierEntrySummaryComponent,
DossierHistoryComponent,
DossierLabComponent,
DossierMedicationComponent,
DossierMiscComponent,
DossierNavigationComponent,
DossierPhysicalComponent,
DossierPdfComponent,
PdfViewerComponent,
BrochureDetailComponent,
//PdfViewerControlsComponent,
TopbarComponent
],
})
export class DossierModule {}