[英]Lazy Module Angular 8 doesn't work, following the Official Angular tutorial
I'm following exactly this tuto from the official documentation :我正在遵循官方文档中的这个教程:
https://angular.io/guide/lazy-loading-ngmodules https://angular.io/guide/lazy-loading-ngmodules
that allow us to create lazy loaded modules in Angular 8允许我们在 Angular 8 中创建延迟加载的模块
I have an error that i can't figure out and i don't find any similar issue on internet..我有一个我无法弄清楚的错误,我在互联网上没有找到任何类似的问题..
I have this error :我有这个错误:
ERROR Error: Uncaught (in promise): Error: No NgModule metadata found for 'undefined'.
Error: No NgModule metadata found for 'undefined'.
at NgModuleResolver.resolve (compiler.js:20665)
at CompileMetadataResolver.getNgModuleMetadata (compiler.js:19794)
at JitCompiler._loadModules (compiler.js:25582)
at JitCompiler._compileModuleAndComponents (compiler.js:25565)
at JitCompiler.compileModuleAsync (compiler.js:25527)
at CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:216)
at MergeMapSubscriber.project (router.js:5391)
at MergeMapSubscriber._tryNext (mergeMap.js:46)
at MergeMapSubscriber._next (mergeMap.js:36)
at MergeMapSubscriber.next (Subscriber.js:49)
at resolvePromise (zone-evergreen.js:797)
at resolvePromise (zone-evergreen.js:754)
at zone-evergreen.js:858
at ZoneDelegate.invokeTask (zone-evergreen.js:391)
at Object.onInvokeTask (core.js:34182)
at ZoneDelegate.invokeTask (zone-evergreen.js:390)
at Zone.runTask (zone-evergreen.js:168)
at drainMicroTaskQueue (zone-evergreen.js:559)
This error appears in the browser console on the button click.单击按钮时,此错误出现在浏览器控制台中。
If you have already faced this issue, please help me... I'm stuck...如果您已经遇到过这个问题,请帮助我...我被卡住了...
UPDATE :更新 :
In app-routing.module.ts在 app-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{
path: 'astreintes',
loadChildren : () => import('./astreintes/astreintes.module').then(module => {module.AstreintesModule})
},
{
path: 'profile',
loadChildren : () => import('./profile/profile.module').then(module => {module.ProfileModule})
},
{
path: '',
redirectTo: '',
pathMatch: 'full'
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
In profile-routing.module.ts在 profile-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { UserProfileComponent } from './user-profile/user-profile.component';
const routes: Routes = [
{
path : '',
component : UserProfileComponent
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class ProfileRoutingModule { }
In astreinte-routing.module.ts ( Astreinte is a french word ):在 astreinte-routing.module.ts(Astreinte 是一个法语词):
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AstreintesListComponent } from './astreintes-list/astreintes-list.component';
const routes: Routes = [
{
path: '',
component: AstreintesListComponent
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class AstreintesRoutingModule { }
My components only show我的组件只显示
<p>profile works!</p>
and和
<p>astreintes-list works!</p>
Your lambda functions return nothing.您的 lambda 函数不返回任何内容。 Either remove the brackets or add return statements.
删除括号或添加 return 语句。
Either:任何一个:
loadChildren : () => import('./profile/profile.module').then(module => {return module.ProfileModule})
or:或者:
loadChildren : () => import('./profile/profile.module').then(module => module.ProfileModule)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.