Open In App

Difference between declarations and entryComponents in AngularJS

declarations: Array<Type | any[]>




import { BrowserModule } from
    '@angular/platform-browser';
import { NgModule } from '@angular/core';
 
import { HeaderComponent } from
    './header/header.component';
import { ListComponent } from
    './list/list.component';
import { DetailComponent } from
    './detail/detail.component';
 
import { AppComponent } from
    './app.component';
 
@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    ListComponent,
    DetailComponent,
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Difference between entry Component and Declaration: 
 

entry Component Declarations
entryComponent array ensures that tree-shaking doesn’t break the application. Declarations array ensures module encapsulation.
entryComponents are used to register components for offline computation in a module. These components are referenced here as they not referenced anywhere else in HTML template. Declarations are used to make Directives(components, pipes etc.) in a specific module.
Components used for router configuration can be added implicitly. Directives, components, and pipes are matched against the HTML only if they are declared or imported.
Array of components are added by ComponentFactoryReolver. Array of components can be found in HTML template.

 

Article Tags :