What is entryComponents in angular ngModule?

Note: EntryConponent is Deprecated from Angular 9.0.0
See the angular docs form more details.

This is for dynamically added components that are added using ViewContainerRef.createComponent(). Adding them to entryComponents tells the offline template compiler to compile them and create factories for them.

The components registered in route configurations are added automatically to entryComponents as well because router-outlet also uses ViewContainerRef.createComponent() to add routed components to the DOM.

Offline template compiler (OTC) only builds components that are actually used. If components aren’t used in templates directly the OTC can’t know whether they need to be compiled. With entryComponents you can tell the OTC to also compile this components so they are available at runtime.

What is an entry component? (angular.io)

NgModule docs (angular.io)

Defines the components that should be compiled as well when this component is defined. For each components listed here, Angular will create a ComponentFactory and store it in the ComponentFactoryResolver.

If you don’t list a dynamically added component to entryComponents you’ll get an error message a bout a missing factory because Angular won’t have created one.

See also https://angular.io/docs/ts/latest/cookbook/dynamic-component-loader.html

Leave a Comment