Angular5中如何延迟加载外部模块?
How lazy load an external module in Angular 5?
我正在尝试将一个外部模块(我编写的)延迟加载到主应用程序中,但我遇到了一些错误,但首先我想问你是否必须构建到 /dist 首先是外部模块,还是我必须使用源文件?
主外app/module都写成Angular5
错误:
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)
您必须为此外部模块编写一个包装器模块,然后延迟加载该包装器模块。 Angular 不会将外部节点模块加载为惰性模块,所以我采用了相同的方法
我正在尝试将一个外部模块(我编写的)延迟加载到主应用程序中,但我遇到了一些错误,但首先我想问你是否必须构建到 /dist 首先是外部模块,还是我必须使用源文件?
主外app/module都写成Angular5
错误:
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)
您必须为此外部模块编写一个包装器模块,然后延迟加载该包装器模块。 Angular 不会将外部节点模块加载为惰性模块,所以我采用了相同的方法