简体   繁体   English

如何在 Angular 5 中延迟加载外部模块?

[英]How lazy load an external module in Angular 5?

I'm trying to lazy load an external module (I wrote) into a main application, and I've got some errors, but first of all I wanted to ask you whether I have to build into /dist the external module first, or I have to use the source files?我正在尝试将外部模块(我编写的)延迟加载到主应用程序中,但我遇到了一些错误,但首先我想问您是否必须先将外部模块构建到/dist中,或者我必须使用源文件吗?

Both main and external app/module are written with Angular 5主要和外部应用程序/模块都是用 Angular 5 编写的

Error:错误:

ERROR in Error: No NgModule metadata found for 'AppModule'.
    at NgModuleResolver.resolve (/Users/me/Dev/Work/mobile-shop-frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:20291:23)
    at CompileMetadataResolver.getNgModuleMetadata (/Users/me/Dev/Work/mobile-shop-frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:15244:60)
    at visitLazyRoute (/Users/me/Dev/Work/mobile-shop-frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:31182:104)
    at AotCompiler.listLazyRoutes (/Users/me/Dev/Work/mobile-shop-frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:31150:20)
    at AngularCompilerProgram.listLazyRoutes (/Users/me/Dev/Work/mobile-shop-frontend/node_modules/@angular/compiler-cli/src/transformers/program.js:156:30)
    at Function.NgTools_InternalApi_NG_2.listLazyRoutes (/Users/me/Dev/Work/mobile-shop-frontend/node_modules/@angular/compiler-cli/src/ngtools_api.js:44:36)
    at AngularCompilerPlugin._getLazyRoutesFromNgtools (/Users/me/Dev/Work/mobile-shop-frontend/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:246:66)
    at Promise.resolve.then.then (/Users/me/Dev/Work/mobile-shop-frontend/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:537:50)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)

You have to write a wrapper module for this external module and then lazy load this wrapper module.您必须为此外部模块编写包装器模块,然后延迟加载此包装器模块。 Angular doesn't load external node modules as lazy module so I followed same approach Angular 不会将外部节点模块加载为惰性模块,因此我采用了相同的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM