Thanks for your article!
But when I applied to my project, I got error in line:
moduleFactory = await this.injector
.get(Compiler)
.compileModuleAsync(ngModuleOrNgModuleFactory);
and message: âError: Runtime compiler is not loadedâ
That seem this.injector.get(Compiler) does not work. I think I missing include compiler on build prod but I donât know how to include it. Please help me! (I build prod with --aot=true)
Thank you!
Can you confirm if you have IVY enabled and on Angular 9+ ?
Also, with AOT you shouldnât be getting into this code as the loaded module should be of type NgModuleFactory.
I just checked and that project has not enabled with ivy. Thanks for quick response!
By the way, some my library does not build with ivy right now, so I should build like traditional (not ivy enabled), but I cannot generate ngfactory file (already set skipTemplateCodegen to false). I got error âtypeerror-cannot-read-property-type-of-undefinedâ. Do you know it?
I found the reason, but I donât know how to fix.
When set angularCompilerOptions -> skipTemplateCodegen to false, the angular cli cannot build raw typescript class (does not have any decorator for class such as @Component, @InjectableâŚ). And it throw the error: âCannot read property âtypeâ of nullâ.
Hope this makes selector-based component work the main angular project.
For the Angular libraries, I havenât used this approach. I have been using libraries with ivy disabled & NOT expanded the selector-based components approach that is part of the library to be loaded in the main project.
Thank you, I clear my mindset and now Iâm using angular library architecture but ref direct from main app to library, and compile with ivy, the dynamic component work well.