2017-06-09 17:48:53 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# Bootstrapping
  
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#### Prerequisites
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								A basic understanding of the following:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  [JavaScript Modules vs. NgModules ](guide/ngmodule-vs-jsmodule ). 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< hr  / >  
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								An NgModule describes how the application parts fit together.
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Every application has at least one Angular module, the _root_  module
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								that you bootstrap to launch the application.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								By convention, it is usually called `AppModule` .
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-16 14:20:56 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								If you use the [Angular CLI ](cli ) to generate an app, the default `AppModule`  is as follows:
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/* JavaScript imports */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import { BrowserModule } from '@angular/platform -browser';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import { NgModule } from '@angular/core ';
							 
						 
					
						
							
								
									
										
										
										
											2018-05-30 16:12:49 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import { FormsModule } from '@angular/forms ';
							 
						 
					
						
							
								
									
										
										
										
											2018-07-28 10:47:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import { HttpClientModule } from '@angular/common/http ';
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import { AppComponent } from './app.component';
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/* the AppModule class with the @NgModule  decorator */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@NgModule ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  declarations: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    AppComponent
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  imports: [
							 
						 
					
						
							
								
									
										
										
										
											2018-05-30 16:12:49 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    BrowserModule,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    FormsModule,
							 
						 
					
						
							
								
									
										
										
										
											2018-07-28 10:47:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    HttpClientModule
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  bootstrap: [AppComponent]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class AppModule { }
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								After the import statements is a class with the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								**`@NgModule` ** [decorator ](guide/glossary#decorator '"Decorator" explained' ).
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The `@NgModule`  decorator identifies `AppModule`  as an `NgModule`  class.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								`@NgModule`  takes a metadata object that tells Angular how to compile and launch the application. 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								*  **_declarations_**— this application's lone component. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  **_imports_**— import `BrowserModule`  to have browser specific services such as DOM rendering, sanitization, and location. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  **_providers_**— the service providers. 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								*  **_bootstrap_**— the _root_  component that Angular creates and inserts 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								into the `index.html`  host web page.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-16 14:20:56 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The default application created by the Angular CLI only has one component, `AppComponent` , so it
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								is in both the `declarations`  and the `bootstrap`  arrays.
							 
						 
					
						
							
								
									
										
										
										
											2017-11-03 11:13:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{@a  declarations}
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## The `declarations` array
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The module's `declarations`  array tells Angular which components belong to that module.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								As you create more components, add them to `declarations` .
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You must declare every component in exactly one `NgModule`  class.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								If you use a component without declaring it, Angular returns an
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								error message.
							 
						 
					
						
							
								
									
										
										
										
											2017-11-03 11:13:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The `declarations`  array only takes declarables. Declarables
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								are components, [directives ](guide/attribute-directives ) and [pipes ](guide/pipes ).
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								All of a module's declarables must be in the `declarations`  array.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Declarables must belong to exactly one module. The compiler emits
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								an error if you try to declare the same class in more than one module.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								These declared classes are visible within the module but invisible
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								to components in a different module unless they are exported from
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								this module and the other module imports this one.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								An example of what goes into a declarations array follows:
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  declarations: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    YourComponent,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    YourPipe,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    YourDirective
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								A declarable can only belong to one module, so only declare it in
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								one `@NgModule` . When you need it elsewhere,
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import the module that has the declarable you need in it.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								**Only `@NgModule`  references** go in the `imports`  array.
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-03 11:13:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Using directives with `@NgModule`
  
						 
					
						
							
								
									
										
										
										
											2017-11-03 11:13:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Use the `declarations`  array for directives.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								To use a directive, component, or pipe in a module, you must do a few things:
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								1.  Export it from the file where you wrote it. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								2.  Import it into the appropriate module. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								3.  Declare it in the `@NgModule`  `declarations`  array. 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-03 11:13:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Those three steps look like the following. In the file where you create your directive, export it.
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The following example, named `ItemDirective`  is the default directive structure that the CLI generates in its own file, `item.directive.ts` :
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example  path = "bootstrapping/src/app/item.directive.ts"  region = "directive"  header = "src/app/item.directive.ts" > < / code-example >  
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The key point here is that you have to export it so you can import it elsewhere. Next, import it
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								into the NgModule, in this example `app.module.ts` , with a JavaScript import statement:
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example  path = "bootstrapping/src/app/app.module.ts"  region = "directive-import"  header = "src/app/app.module.ts" > < / code-example >  
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								And in the same file, add it to the `@NgModule`  `declarations`  array:
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example  path = "bootstrapping/src/app/app.module.ts"  region = "declarations"  header = "src/app/app.module.ts" > < / code-example >  
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Now you could use your `ItemDirective`  in a component. This example uses `AppModule` , but you'd do it the same way for a feature module. For more about directives, see [Attribute Directives ](guide/attribute-directives ) and [Structural Directives ](guide/structural-directives ). You'd also use the same technique for [pipes ](guide/pipes ) and components.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Remember, components, directives, and pipes belong to one module only. You only need to declare them once in your app because you share them by importing the necessary modules. This saves you time and helps keep your app lean.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  imports}
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## The `imports` array
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The module's `imports`  array appears exclusively in the `@NgModule`  metadata object.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								It tells Angular about other NgModules that this particular module needs to function properly.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This list of modules are those that export components, directives, or pipes
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								that the component templates in this module reference. In this case, the component is
							 
						 
					
						
							
								
									
										
										
										
											2018-05-30 16:12:49 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`AppComponent` , which references components, directives, or pipes in `BrowserModule` , 
						 
					
						
							
								
									
										
										
										
											2018-07-28 10:47:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`FormsModule` , or  `HttpClientModule` . 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								A component template can reference another component, directive,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								or pipe when the referenced class is declared in this module or
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								the class was imported from another module.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  bootstrap-array}
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## The `providers` array
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The providers array is where you list the services the app needs. When
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								you list services here, they are available app-wide. You can scope
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								them when using feature modules and lazy loading. For more information, see
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[Providers ](guide/providers ).
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## The `bootstrap` array
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The application launches by bootstrapping the root `AppModule` , which is
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								also referred to as an `entryComponent` .
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Among other things, the bootstrapping process creates the component(s) listed in the `bootstrap`  array
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								and inserts each one into the browser DOM.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Each bootstrapped component is the base of its own tree of components.
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Inserting a bootstrapped component usually triggers a cascade of
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								component creations that fill out that tree.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								While you can put more than one component tree on a host web page,
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								most applications have only one component tree and bootstrap a single root component.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This one root component is usually called `AppComponent`  and is in the
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								root module's `bootstrap`  array.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-03 11:13:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## More about Angular Modules
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For more on NgModules you're likely to see frequently in apps,
							 
						 
					
						
							
								
									
										
										
										
											2018-04-05 20:29:54 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								see [Frequently Used Modules ](guide/frequent-ngmodules ).