I have this in my app.module.ts:
import { BrowserModule } from '@angular/platform-browser'; import { ErrorHandler, NgModule } from '@angular/core'; import { HttpModule, Http } from '@angular/http'; import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular'; import { EliteApi } from '../shared/shared'; import { MyApp } from './app.component'; import { MyTeams, Tournaments, TeamDetails, Teams, TeamHome, Standings } from '../pages/pages'; import { StatusBar } from '@ionic-native/status-bar'; import { SplashScreen } from '@ionic-native/splash-screen'; @NgModule({ declarations: [ MyApp, MyTeams, TeamDetails, Tournaments, Teams, TeamHome, Standings ], imports: [ BrowserModule, IonicModule.forRoot(MyApp), HttpModule ], bootstrap: [IonicApp], entryComponents: [ MyApp, MyTeams, TeamDetails, Tournaments, Teams, TeamHome, Standings ], providers: [ HttpModule, StatusBar, SplashScreen, { provide: ErrorHandler, useClass: IonicErrorHandler }, EliteApi ] }) export class AppModule { }
At the moment my declarations
and entryComponents
both are exactly the same. They contain all of the page/components that I built for my app. If I remove any entry from any of the properties I get error in angular2.
My question is if they are always the same then what is the need for these properties? I think I am definitely missing some point here. When would entryComponents and declaractions be different from one another?
An entry component is any component that Angular loads imperatively, (which means you're not referencing it in the template), by type. You specify an entry component by bootstrapping it in an NgModule, or including it in a routing definition.
Declarations are used to make directives. Providers are used to make services. Imports makes the exported declarations of other modules available in the current module. Used to declare components, directives, pipes that belongs to the current module.
The entryComponents array is used to define only components that are not found in html and created dynamically. Angular requires this hint to find entry component and compile them.
declarations: This property tells about the Components, Directives and Pipes that belong to this module. exports: The subset of declarations that should be visible and usable in the component templates of other NgModules.
The entryComponents
array is used to define only components that are not found in html and created dynamically with ComponentFactoryResolver
. Angular needs this hint to find them and compile. All other components should just be listed in the declarations array.
Here's the documentation on angular site
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With