My Angular application is facing challenges when loading dynamic components. Everything works smoothly with the JIT ng serve or ng build
compilation. Even with AOT
ng serve --prod or ng build --prod
, I can still successfully build the application. Lazy loading modules are also functioning as expected. However, when an event is triggered to load a dynamic component from the landing page, I encounter the following error:
vendor.fbd3ddffb0a9e35bbf55.bundle.js:1 ERROR Error: Uncaught (in promise):
Error: Runtime compiler is not loaded
Error: Runtime compiler is not loaded
at Z (vendor.fbd3ddffb0a9e35bbf55.bundle.js:1)
...
<p>To resolve the above error, I applied an injector in the dynamic component like this:</p>
<pre><code>export class DynamicComponent {
private injector: Injector;
private compiler: Compiler;
constructor(injector: Injector) {
this.injector = ReflectiveInjector.resolveAndCreate(COMPILER_PROVIDERS,
injector);
this.compiler = this.injector.get(Compiler);
}
}
After fixing the previous error, I encountered the following issue:
vendor.fbd3ddffb0a9e35bbf55.bundle.js:1 ERROR Error: Uncaught (in promise):
Error: No NgModule metadata found for 'l'
Error: No NgModule metadata found for 'l'
at t.FDXN.t.resolve (dynamic.module.c493eec4648091b2c9b3.chunk.js:1)
...
<p>Despite extensive research on the internet and platforms like Stack Overflow, I have been unable to find a solution that works for me.</p>
<p>The structure of my dynamic component is as follows:</p>
<pre><code>import { Component, Input, Output, ViewContainerRef, Compiler, ..., }
...
@Component({
selector: 'app-dynamic-viewer',
...
})
<p>Application environment:</p>
<pre><code>@angular/cli: 1.3.0-beta.1
node: 6.9.4
os: win32 x64
@angular version: 4.3.6
If you have any workaround solutions or insights, please feel free to share. Any input would be greatly appreciated.