What is entryComponents in angular ngModule ?
Last Updated :
28 Apr, 2025
The entryComponent is the component which loads angular by force, that means these components are not referenced in the HTML template. In most of the cases, Angular loads a component when it is explicitly declared in the component template. But this is not the case with entryComponents. The entryComponents are only loaded dynamically and are never referenced in the component template. It refers to the array of components that are not found in HTML, instead are added by the ComponentFactoryResolver. Firstly, Angular creates a component factory for each of the bootstrap entryComponents by ComponentFactoryResolver class and then, at run-time, it will use the factories to instantiate the components.
abstract class ComponentFactoryResolver {
static NULL: ComponentFactoryResolver
abstract resolveComponentFactory(component: Type): ComponentFactory
}
Types of entry components in Angular:
- The bootstrapped root component
- Routed component (A component you specify in a route)
Bootstrapped entryComponent: At the time of application launch or during bootstrap process, the bootstrap component is loaded in DOM (Document Object Model) by Angular.
html
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
The bootstrap component is an entryComponent that provides the entry point to the application. Angular loads AppComponent by default as it is listed in @NgModule.bootstrap.
app.module.ts
Routed entryComponent: This sort of components are declared components and are added as an array inside the declarations section of the app. But, you may need to reference to a component by its class. Router components are not specified explicitly in the HTML of a component but, are registered in routes array. These components are also loaded dynamically and thus Angular needs to know about them. These components are added in two places:
app-routing.module.ts
html
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { ListComponent } from './list/list.component';
import { DetailComponent } from './detail/detail.component';
const routes: Routes = [
{
path:'',
redirectTo:'/contact',
pathMatch:'full'
},
{
path: 'list',
component: ListComponent
},
{
path: 'detail',
component: DetailComponent
},
{
path:'**',
redirectTo:'/not-found'
}
];
@NgModule({
imports:[RouterModule.forRoot(routes)],
exports:[RouterModule]
})
export class AppRoutingModule{
}
You don't need to add the component to entryComponent array explicitly, Angular does that automatically. The compiler adds all the router component to the entryComponent array.
app.module.ts
Need of entryComponent Array: Angular only includes those components in the final bundle that has been referenced in the template. This is done to reduce the size of the final package by not including unwanted components. But this would break the final application as all the entryComponents would never be included in the final package (as they have never been referenced). Therefore we need to register these components under entyComponents array for Angular to include them in the bundle.
Similar Reads
Standalone Components In Angular In Angular, standalone components are a new feature that allows you to create components without the need for a module. This can simplify your application structure and reduce boilerplate code. This article will guide you through the concept of standalone components, including different approaches,
4 min read
Use component from another module -Angular Angular's modular architecture is one of its core strengths, allowing it to break down large applications into smaller, manageable pieces. A key aspect of modularity in Angular is the ability to share components across different modules. You can promote code reuse and maintainability by exporting an
6 min read
Introduction To Components And Templates in Angular Angular is a powerful framework for building dynamic, single-page web applications. One of the core concepts that make Angular so effective is its use of components and templates. Components and templates are the building blocks of any Angular application, allowing developers to create reusable, mai
6 min read
Component Lifecycle in Angular In Angular, Components are the fundamental building blocks of an application. Understanding the lifecycle of these components is crucial for effective Angular Development. Angular provides several lifecycle hooks that allow developers to tap into key moments in a Componentâs lifecycle and execute cu
3 min read
Angular PrimeNG Sidebar Component Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the Sidebar component in Angular PrimeNG. We will also lear
5 min read
What is CommonModule in Angular 10 ? In this article, we are going to see what is CommonModule in Angular 10 and how to use it. CommonModule is used to export all the basic Angular directives and pipes. It is re-exported when we import BrowserModule into our angular application, BrowserModule is automatically imported into our applicat
2 min read
What's the difference between an Angular Component and Module? In this article, we will explore the Components & Modules in Angular, along with knowing the basic implementation & lastly, will know the differences between them. Component: In Angular, a Component is a piece of code that represents a view. It is responsible for rendering the content and ha
6 min read
What is the AppModule in Angular ? In Angular, AppModule plays an important role as the entry point to an Angular application. In this article, we'll learn about what AppModule is, its structure, and its significance in Angular applications. We'll also look at some examples to have a clear understanding. Table of Content What is AppM
4 min read
Components in Angular 8 The component is the basic building block of Angular. It has a selector, template, style, and other properties, and it specifies the metadata required to process the component. Creating a Component in Angular 8: To create a component in any angular application, follow the below steps: Get to the ang
2 min read
What is NgStyle in Angular 10 ? In this article, we are going to see what is NgStyle in Angular 10 and how to use it. NgStyle is used to add some style to an HTML element Syntax: <element [ngStyle] = "typescript_property"> Approach:Â Create the Angular app to be usedIn app.component.html make an element and sets its class us
1 min read