我正在通过重新设计路由,将其从字符串引用的延迟加载更改为从对import
的调用的延迟加载。
我的问题是,每次导航到页面之一时,都会收到以下错误消息:没有为“ [对象模块]”找到NgModule元数据。
consolelogs.js:49 ERROR Error: Uncaught (in promise): Error: No NgModule metadata found for '[object Module]'.
Error: No NgModule metadata found for '[object Module]'.
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.wrapIntoObservable.pipe.Object [as project] (router.js:5369)
at MergeMapSubscriber._tryNext (mergeMap.js:46)
at MergeMapSubscriber._next (mergeMap.js:36)
at MergeMapSubscriber.next (Subscriber.js:49)
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.wrapIntoObservable.pipe.Object [as project] (router.js:5369)
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.scheduleMicroTask (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)
at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:469)
at invokeTask (zone-evergreen.js:1603)
是什么原因导致此问题?
答案 0 :(得分:0)
事实证明,我对路由使用了延迟加载,但是无法正确导入要加载的页面模块。请注意缺少对then()
的呼叫。
{
path: "references",
children: [
{
path: "",
loadChildren: () =>
import(
"app/applications/requirements/requirements-references/requirements-references.module"
).then(m => m.RequirementsReferencesPageModule)
},
{
path: ":referenceId",
loadChildren: () =>
import(
"app/applications/requirements/requirements-references-detail/requirements-references-detail.module"
)
}
]
}
我错过了导入的then
部分。记住要遵循以下模式:
import("path-to-your-module").then(m => m.NameOfModule)