Reputation: 431
I am trying to implement an Angular library which will encapsulate the logic required to add dynamic components to the DOM. Applications that consume this library must be allowed to provide a list of Components that will be dynamic, and then define "outlets" where these dynamic components must be inserted at runtime.
My code is heavily inspired by two articles:
The basic structure of my code is as below:
ng-dynamic-components
with a module NgDynamicComponentsModule
, which allows the consumer to define a list of components that should be available for adding to the DOM at runtimeViewContainerRef
dynamic-test-app
that imports this library and consumes it with some test components that are dynamically injected -- OneComponent
, TwoComponent
, and ThreeComponent
My code is available at: https://github.com/kiranjholla/ng-dynamic-components. To run my code, just clone this Git repository and then type in npm install
and npm start
. This will first build the library using the option --prod
, and then build the test application using the options --prod --aot=false --buildOptimizer=false
, and then start a http-server
instance to serve the dist
folder
Now my questions: the above code works only when the application is built with --aot=false --buildOtimizer=false
; when AOT is enabled, I get an error stating that the compiler is unavailable.
But, I have already provided the Compiler specifically using the JitCompilerFactory
. How can I get it to work with AOT??
Any help/pointers, greatly appreciated.
Upvotes: 1
Views: 278