简体   繁体   English

根据官方 Angular 教程,延迟模块 Angular 8 不起作用

[英]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.

相关问题 Angular2依赖项注入无法按照官方教程中的描述进行操作 - Angular2 dependency injection doesn't work as described in official tutorial Angular 4延迟加载模块不适用于指定的子插座 - Angular 4 lazy load module doesn't work with named child outlet Angular 4-延迟加载-模块路由无法正常工作 - Angular 4 - lazy loading - module routing doesn't work as well 尝试使用 forRoot() 为延迟加载的组件延迟加载与 Angular Material 相关的自定义模块不起作用 - Trying to lazy load Angular Material related custom module for lazy loaded components using forRoot() doesn't work 角度cli延迟加载不起作用 - Angular cli lazy loading doesn't work Angular 4-延迟加载路线不起作用 - Angular 4 - Lazy Loading routes doesn't work Angular 7,命名路由器插座在延迟加载模块中不起作用 - Angular 7, named router outlet doesn't work inside lazy loaded module Angular2不适用于Lazy模块加载的自定义重用策略 - Angular2 doesn't work Custom Reuse Strategy with Lazy module loading 延迟加载模块中的角子级路由无法完全正常工作 - Angular children routes in Lazy Loaded module don't completely work Angular 2教程上的Meteor JS路由不起作用 - Meteor JS Routing on Angular 2 Tutorial doesn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM