Description
Please provide us with the following information:
OS?
macOS Sierra, Ubuntu 16.04
Versions.
angular-cli: 1.0.0-beta.19-3
node: 6.9.1
os: darwin x64
Repro steps.
I've an angular-2 app build with angular-cli and one of the functionality is to list down a list of all the events and clicking on one event displays event details in 3 tabs - Overview, Photos & Tickets.
The way I've developed this is I've all the events stored in my db and also the content for Overview, Photos and Tickets tabs are in DB. So this way I can just have one component which renders 3 tabs and populates each tab content fetched from DB. Now the interesting bit is most of the events will have same layout and sections for each tab, but for some there can be different layout required. So to address this what I'm doing is along with the content of each tab (overview, photos, tickets), I also store the name of the component which will render this event.
I somehow managed to get the component from the name of the component usingComponentFactoryResolver
andViewContainerRef
and all works fine, but problem arises when I try to make a build for production environment -ng build --prod
- where angular-cli kicks webpack's tree-shaking and with that all my components which are not actually referenced/imported in the code but are dynamically created/rendered based on the data retrieved from db are dropped and my app crashes since it cannot find those components. In my NgModule definition, I've declared these dynamic components underentryComponents
as well.
The log given by the failure.
error_handler.js:53Error: No component factory found for undefined
at e [as constructor] (errors.js:24)
at new e (component_factory_resolver.js:21)
at t.resolveComponentFactory (component_factory_resolver.js:30)
at tInjector.t.resolveComponentFactory (component_factory_resolver.js:55)
at t.ngOnChanges (control-factory.directive.ts:29)
at Wrapper_t.detectChangesInternal (wrapper.ngfactory.js:34)
at _View_t1.detectChangesInternal (component.ngfactory.js:146)
at _View_t1.t.detectChanges (view.js:229)
at _View_t0.t.detectContentChildrenChanges (view.js:247)
at _View_t0.detectChangesInternal (component.ngfactory.js:78)