angular - “ng serve”时出错无法读取未定义的属性“loadChildren”
问题描述
我正在处理我的项目,我想延迟加载我的模块,它工作正常,但是当我“ng serve”m 代码时,我收到此错误 “无法读取未定义的属性 'loadChildren'”
这是我的应用路由模块
export const appRoutes: Routes = [
{
path: '',
redirectTo: 'login',
pathMatch: 'full',
canActivate: [AuthGuard]
},
{ path: 'login', component: LoginComponent },
{
path: 'corrrisk',
component: WelcomeComponent,
children: [
{ path: '', component: CorrriskHomeComponent, pathMatch: 'full' },
{
path: 'security',
loadChildren: './modules/security/security.module#CorrSecurityModule' ,
data: { preload: false }
},
{
path: 'setup',
loadChildren: './modules/setup/setup.module#CorrSetupModule',
data: { preload: true }
},
{
path: 'limit',
loadChildren: './modules/limits/limits.module#CorrLimitModule'
},
{
path: 'businesspolicy',
loadChildren:
'./modules/businesspolicy/businesspolicy.module#CorrBusinessPolicyModule',
data: { preload: false }
}
]
}
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes, {
preloadingStrategy: SelectivePreloadingStrategy
})
],
exports: [RouterModule],
providers: [SelectivePreloadingStrategy]
})
export class AppRoutingModule {}
这是我的应用程序模块代码
@NgModule({
declarations: [
AppComponent,
LoginComponent,
WelcomeComponent,
CorrriskHomeComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
MatIconModule,
DxAccordionModule,
FormsModule,
ReactiveFormsModule,
HttpClientModule,
AppRoutingModule,
DevExtremeModule,
CorrOperationsModule,
CorrCommonModule,
CorrMISModule,
NgReduxModule
],
providers: [
httpInterceptorProviders,
appStoreProviders,
{ provide: LOCALE_ID, useValue: 'en-US' }
],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(
ngRedux: NgRedux<any>,
@Inject(AppStore) public store: Redux.Store<AppStateRedux>,
overlayContainer: OverlayContainer
) {
overlayContainer.getContainerElement().classList.add('unicorn-dark-theme');
ngRedux.configureStore(rootReducer, {}, [thunk], []);
}
}
当我在应用程序路由文件中放置空间时,它编译得很好。请告诉我上面代码中有什么问题。
解决方案
我能够通过使用 AOT 激活 Ivy 渲染器来修复错误:
https://angular.io/guide/ivy#aot-and-ivy
您可以在angular.json中激活它
{
"projects": {
"my-existing-project": {
"architect": {
"build": {
"options": {
...
"aot": true,
}
}
}
}
}
}
推荐阅读
- python - 如何以正确的方式捕获连接被拒绝错误?
- eclipse - 如何在 Eclipse 中设置提交消息模板
- c++ - 如何在 Linux 的 Visual Studio Code 中链接 SFML 库?
- javascript - Alasql - 单个 promise 语句中的多个 sheetid
- java - 如何在 Comparator 的 compare() 方法中更改变量值
- java - Xamarin Android:LinearLayout 背景和 Drawable Left 无法正确显示
- java - 来自外部 API 的“无法反序列化实例”
- javascript - 为什么白名单不会出现错误模型 NestJs 的错误
- c# - 将 Object 转换为泛型类型。对象必须实现 IConvertible
- java - 将自定义属性文件转换为java中的复杂类型对象