2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  # Angular 2 Glossary
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  Angular 2 has a vocabulary of its own.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  Most Angular 2 terms are everyday English words
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  with a specific meaning within the Angular system.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  We have gathered here the most prominent terms
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  and a few less familiar ones that have unusual or
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  unexpected definitions.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  [A](#A) [B](#B) [C](#C) [D](#D) [E](#E) [F](#F) [G](#G) [H](#H) [I](#I)
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  [J](#J) [K](#K) [L](#L) [M](#M) [N](#N) [O](#O) [P](#P) [Q](#Q) [R](#R)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  [S](#S) [T](#T) [U](#U) [V](#V) [W](#W) [X](#X) [Y](#Y) [Z](#Z)
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="A"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Annotation
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    In practice a synonym for [Decoration](#decoration).
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								 :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Attribute Directive
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    A category of [Directive](#directive) that can listen to and modify the behavior of
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    other HTML elements, attributes, properties, and components. They are usually represented
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    as HTML attributes, hence the name.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-11 15:20:07 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    The `ngClass` directive for adding and removing CSS class names is a good example of
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    an Attribute Directive.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="B"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 16:52:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Barrel
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    A **barrel** is an Angular library module consisting of a logical grouping of single-purpose modules
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    such as `Component` and `Directive`.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 16:52:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Familiar barrels include `angular2/core`, `angular2/common`, `angular2/platform/browser`,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    `angular2/http`, and `angular2/router`.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Barrels are packaged and shipped as [**bundles**](#bundle) that
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 16:52:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    we may load with script tags in our `index.html`.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 16:52:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    The script, `angular2.dev.js`, is a bundle.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 16:52:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Learn more in "[Modules, barrels and bundles](https://github.com/angular/angular/blob/master/modules/angular2/docs/bundles/overview.md)".
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Binding
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Almost always refers to [Data Binding](#data-binding) and the act of
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    binding an HTML object property to a data object property.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    May refer to a [Dependency Injection](#dependency-injection) binding
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    between a "token" or "key" and a dependency [provider](#provider).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    This more rare usage should be clear in context.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Bootstrap
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    We launch an Angular application by "bootstrapping" it with the `bootstrap` method.
							 
						 
					
						
							
								
									
										
										
										
											2015-10-31 13:05:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    The `bootstrap` method identifies an application's top level "root" [Component](#component)
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    and optionally registers service [providers](#provider) with the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    [dependency injection system](#dependency-injection).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-31 13:05:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    One can bootstrap multiple apps in the same `index.html`, each with its own top level root.
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 16:52:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Bundle
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Angular JavaScript libraries are shipped in **bundles** within an **npm package**
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    such as [angular2](https://www.npmjs.com/package/angular2).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 16:52:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    The scripts `angular2.dev.js`, `http.js`, `router.js`, and `Rx.js` are
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    familiar examples of bundles.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 16:52:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    A bundle contains one more more [**barrels**](#barrel)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    and each barrel contains a collection of logically related [modules](#module)
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 16:52:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Familiar barrels include `angular2/core`, `angular2/common`, `angular2/platform/browser`,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    `angular2/http`, `angular2/router`.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Learn more in "[Modules, barrels and bundles](https://github.com/angular/angular/blob/master/modules/angular2/docs/bundles/overview.md)".
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="C"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Component
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    An Angular class responsible for exposing data
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								    to a [View](#view) and handling most of the view’ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    and user-interaction logic.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    The Component is one of the most important building blocks in the Angular system.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    It is, in fact, an Angular [Directive](directive) with a companion [Template](#template).
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    The  developer applies the `@Component` [decorator](decorator) to
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    the component class, thereby attaching to the class the essential component metadata
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    that Angular needs to create a component instance and render it with its template
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    as a view.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Those familiar with "MVC" and "MVVM" patterns will recognize
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    the Component in the role of "Controller" or "View Model".
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="D"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Data Binding
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Applications display data values to a user and respond to user
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    actions (clicks, touches, keystrokes).
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    We could push application data values into HTML, attach
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    event listeners, pull changed values from the screen, and
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    update application data values ... all by hand.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Or we could declare the relationship between an HTML widget
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    and an application data source ... and let a data binding
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    framework handle the details.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Data Binding is that second approach. Angular has a rich
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    data binding framework with a variety of data binding
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    operations and supporting declaration syntax.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								     The many forms of binding include:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								     * [Interpolation](./template-syntax.html#interpolation)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								     * [Property Binding](./template-syntax.html#property-binding)
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								     * [Event Binding](./template-syntax.html#event-binding)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								     * [Attribute Binding](./template-syntax.html#attribute-binding)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								     * [Class Binding](./template-syntax.html#class-binding)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								     * [Style Binding](./template-syntax.html#style-binding)
							 
						 
					
						
							
								
									
										
										
										
											2015-12-11 15:20:07 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								     * [Two-way data binding with ngModel](./template-syntax.html#ng-model)
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Learn more about data binding in the
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    [Template Syntax](./template-syntax.html#data-binding) chapter.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-31 13:05:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  <a id="decorator"></a> <a id="decoration"></a>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Decorator | Decoration
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    A Decorator is a **function** that adds metadata to a class, its members (properties, methods) and function arguments.
							 
						 
					
						
							
								
									
										
										
										
											2015-10-31 13:05:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Decorators are a JavaScript language [feature](https://github.com/wycats/javascript-decorators), implemented in TypeScript and proposed for ES2016 (AKA ES7).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    We apply a decorator by positioning it
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    immediately above or to the left of the thing it decorates.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-31 13:05:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Angular has its own set of decorators to help it interoperate with our application parts.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Here is an example of a `@Component` decorator that identifies a
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    class as an Angular [Component](#component) and an `@Input` decorator applied to a property
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    of that component.
							 
						 
					
						
							
								
									
										
										
										
											2015-10-31 13:05:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    The elided object argument to the `@Component` decorator would contain the pertinent component metadata.
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    ```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    @Component({...})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    export class AppComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								      constructor(@Inject('SpecialFoo') public foo:Foo) {}
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								      @Input()
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								      name:string;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    ```
							 
						 
					
						
							
								
									
										
										
										
											2015-10-31 13:05:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    The scope of a decorator is limited to the language feature
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    that it decorates. None of the decorations shown here will "leak" to other
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    classes appearing below it in the file.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-31 13:05:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  .alert.is-important
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								      Always include the parentheses `()` when applying a decorator.
							 
						 
					
						
							
								
									
										
										
										
											2015-10-31 13:05:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								      A decorator is a **function** that must be called when applied.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								 :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Dependency Injection
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Dependency Injection is both a design pattern and a mechanism
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    for creating and delivering parts of an application to other
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    parts of an application that request them.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Angular developers prefer to build applications by defining many simple parts
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    that each do one thing well and then wire them together at runtime.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    These parts often rely on other parts. An Angular [Component](#component)
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    part might rely on a service part to get data or perform a calculation. When a
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    part "A" relies on another part "B", we say that "A" depends on "B" and
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    that "B" is a dependency of "A".
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    We can ask a "Dependency Injection System" to create "A"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    for us and handle all the dependencies.
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    If "A" needs "B" and "B" needs "C", the system resolves that chain of dependencies
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    and returns a fully prepared instance of "A".
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Angular provides and relies upon its own sophisticated
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    [Dependency Injection](./dependency-injection.html) system
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    to assemble and run applications by "injecting" application parts
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    into other application parts where and when needed.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    At the core is an [`Injector`](#injector) that returns dependency values on request.
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    The expression `injector.get(token)` returns the value associated with the given token.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    A token is an Angular type (`OpaqueToken`). We rarely deal with tokens directly; most
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    methods accept a class name (`Foo`) or a string ("foo") and Angular converts it
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    to a token. When we write `injector.get(Foo)`, the injector returns
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    the value associated with the token for the `Foo` class, typically an instance of `Foo` itself.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Angular makes similar requests internally during many of its operations
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    as when it creates a [`Component`](#AppComponent) for display.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    The `Injector` maintains an internal map of tokens to dependency values.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    If the `Injector` can't find a value for a given token, it creates
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    a new value using a `Provider` for that token.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    A [Provider](#provider) is a recipe for
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    creating new instances of a dependency value associated with a particular token.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    An injector can only create a value for a given token if it has
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    a `Provider` for that token in its internal provider registry.
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Registering providers is a critical preparatory step.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Angular registers some of its own providers with every injector.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    We can register our own providers. Quite often the best time to register a `Provider`
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    is when we [bootstrap](#bootstrap) the application.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    There are other opportunities to register as well.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Learn more in the [Dependency Injection](./dependency-injection.html) chapter.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								 :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Directive
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    An Angular class responsible for creating, re-shaping, and interacting with HTML elements
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    in the browser DOM. Directives are Angular's most fundamental feature.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    A Directive is almost always associated with an HTML element or attribute.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    We often refer to such an element or attribute as the directive itself.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    When Angular finds a directive in an HTML template,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    it creates the matching directive class instance
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    and gives that instance control over that portion of the browser DOM.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Developers can invent custom HTML markup (e.g., `<my-directive>`) to
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    associate with their custom directives. They add this custom markup to HTML templates
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    as if they were writing native HTML. In this way, directives become extensions of
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    HTML itself.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Directives fall into one of three categories:
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    1. [Components](#component) that combine application logic with an HTML template to
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    render application [views]. Components are usually represented as HTML elements.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    They are the building blocks of an Angular application and the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    developer can expect to write a lot of them.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    1. [Attribute Directives](attribute-directive) that can listen to and modify the behavior of
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    other HTML elements, attributes, properties, and components. They are usually represented
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    as HTML attributes, hence the name.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    1. [Structural Directives](#structural-directive), a directive responsible for
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    shaping or re-shaping HTML layout, typically by adding, removing, or manipulating
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    elements and their children.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="E"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## ECMAScript
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    The [official JavaScript language specification](https://en.wikipedia.org/wiki/ECMAScript).
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    The latest approved version of JavaScript is
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    [ECMAScript 2015](http://www.ecma-international.org/ecma-262/6.0/)
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    (AKA "ES2015" or "ES6") and many Angular 2 developers will write their applications
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    either in this version of the language or a dialect that strives to be
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    compatible with it such as [TypeScript](#typesScript).
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Most modern browsers today only support the prior "ECMAScript 5" (AKA ES5) standard.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Applications written in ES2015 or one of its dialects must be "[transpiled](transpile)"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    to ES5 JavaScript.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Angular 2 developers may choose to write in ES5 directly.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## ECMAScript 2015
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    The lastest released version of JavaScript,
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    [ECMAScript 2015](http://www.ecma-international.org/ecma-262/6.0/)
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    (AKA "ES2015" or "ES6")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## ES2015
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Short hand for "[ECMAScript 2015](#ecmascript=2015)".
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## ES6
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Short hand for "[ECMAScript 2015](#ecmascript=2015)".
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## ES5
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Short hand for "ECMAScript 5", the version of JavaScript run by most modern browsers.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    See [ECMAScript](#ecmascript).
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="F"></a>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								<a id="G"></a>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								<a id="H"></a>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								<a id="I"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Injector
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    An object in the Angular [dependency injection system](#dependency-injection)
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    that can find a named "dependency" in its cache or create such a thing
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    with a registered [provider](#provider).
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Input
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    A directive property that can be the ***target*** of a
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    [Property Binding](./template-syntax.html#property-binding).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Data values flow *into* this property from the data source identified
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    in the template expression to the right of the equal sign.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    See the [Template Syntax](./template-syntax.html#inputs-outputs) chapter.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Interpolation
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    A form of [Property Data Binding](#data-binding) in which a
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    [template expression](#template-expression) between double-curly braces
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    renders as text.  That text may be concatenated with neighboring text
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    before it is assigned to an element property
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    or displayed between element tags as in this example.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  code-example(language="html" escape="html").
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    <label>My current hero is {{hero.name}}</label>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Learn more about interpolation in the
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    [Template Syntax](./template-syntax.html#interpolation) chapter.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="J"></a>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								<a id="K"></a>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								<a id="L"></a>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Lifecycle Hooks
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 21:15:04 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    [Directives](#directive) and [Components](#component) have a lifecycle
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    managed by Angular as it creates, updates and destroys them.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 21:15:04 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Developers can tap into key moments in that lifecycle by implementing
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    one or more of the "Lifecycle Hook" interfaces.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 21:15:04 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Each interface has a single hook method whose name is the interface name prefixed with `ng`.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    For example, the `OnInit` interface has a hook method names `ngOnInit`.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 21:15:04 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Angular calls these hook methods in the following order:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    * `ngOnChanges` - called when an [input](#input)/[output](#output) binding values change
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    * `ngOnInit` - after the first `ngOnChanges`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    * `ngDoCheck` - developer's custom change detection
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    * `ngAfterContentInit` - after component content initialized
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    * `ngAfterContentChecked` - after every check of component content
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    * `ngAfterViewInit` - after component's view(s) are initialized
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    * `ngAfterViewChecked` - after every check of a component's view(s)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    * `ngOnDestroy` - just before the directive is destroyed.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Learn more in the [Lifecycle Hooks](lifecycle-hooks.html) chapter.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								<a id="M"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 16:52:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Module
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Angular apps are modular.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 21:15:04 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    In general, we assemble our application from many modules, both the ones we write ourselves
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 16:52:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    and the ones we acquire from others.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    A typical module is a cohesive block of code dedicated to a single purpose.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 21:15:04 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    A module **exports** something of value in that code, typically one thing such as a class.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    A module that needs that thing, **imports** it.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    The structure of Angular modules and the import/export syntax
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    is based on the [ES2015](#es2015) module standard
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 21:15:04 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    described [here](http://www.2ality.com/2014/09/es6-modules-final.html).
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 21:15:04 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    An application that adheres to this standard requires a module loader to
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    load modules on request and resolve inter-module dependencies.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 21:15:04 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Angular does not ship with a module loader and does not have a preference
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    for any particular 3rd party library (although most samples use SystemJS).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Application developers may pick any module library that conforms to the standard
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 21:15:04 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Modules are typically named after the file in which the exported thing is defined.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 16:52:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    The Angular [DatePipe](https://github.com/angular/angular/blob/master/modules/angular2/src/common/pipes/date_pipe.ts)
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 21:15:04 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    class belongs to a feature module named `date_pipe` in the file `date_pipe.ts`.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Developers rarely access Angular feature modules directly.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 21:15:04 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    We usually import them from public-facing **library modules**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    called [**barrels**](#barrel). Barrels are groups of logically related modules.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    The `angular2/core` barrel is a good example.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-15 16:52:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    Learn more in "[Modules, barrels and bundles](https://github.com/angular/angular/blob/master/modules/angular2/docs/bundles/overview.md)".
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="N"></a>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								<a id="O"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Output
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    A directive property that can be the ***target*** of an
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    [Event Binding](./template-syntax.html#property-binding).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Events stream *out* of this property to the receiver identified
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    in the template expression to the right of the equal sign.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    See the [Template Syntax](./template-syntax.html#inputs-outputs) chapter.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="P"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Pipe
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    An Angular pipe is a function that transforms input values to output values for
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    display in a [view](#view). We use the `@Pipe` [decorator](decorator)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    to associate the pipe function with a name. We then can use that
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    name in our HTML to declaratively transform values on screen.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Here's an example that uses the built-in `currency` pipe to display
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    a numeric value in the local currency.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  code-example(language="html" escape="html").
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    <label>Price: </label>{{product.price | currency}}
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Learn more in the chapter on [pipes](./pipes.html) .
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Provider
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    A Provider creates a new instance of a dependency for the Dependency Injection system.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    It relates a lookup token to code - sometimes called a "recipe" - that can create a dependency value.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    For example, `new Provider(Foo, {useClass: Foo})` creates a `Provider`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    that relates the `Foo` token to a function that creates a new instance of the `Foo` class.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    There are other ways to create tokens and recipes.
							 
						 
					
						
							
								
									
										
										
										
											2015-10-27 12:57:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    See [Dependency Injection](#dependency-injection) chapter to learn more.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="Q"></a>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								<a id="R"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Router
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Most applications consist of many screens or [views](#view).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    The user navigates among them by clicking links and buttons
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    and taking other similar actions that cause the application to
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    replace one view with another.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-10 09:40:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    The Angular [Component Router](./router.html) is a richly featured mechanism for configuring
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    and managing the entire view navigation process including the creation and destruction
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    of views.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-10 09:40:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Routing Component
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    A [Component](#component) with an attached router.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-10 09:40:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    In most cases, the component became attached to a [router](#router) by means
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    of a `@RouterConfig` decorator that defined routes to views controlled by this component.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    The component's template has a `RouterOutlet` element where it can display views produced by the router.
							 
						 
					
						
							
								
									
										
										
										
											2015-12-17 13:49:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-10 09:40:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    It likely has anchor tags or buttons with `RouterLink` directives that users can click to navigate.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="S"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Structural Directive
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    A category of [Directive](#directive) that can
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    shape or re-shape HTML layout, typically by adding, removing, or manipulating
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    elements and their children.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-11 15:20:07 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    The `ngIf` "conditional element" directive and the `ngFor` "repeater" directive are
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    good examples in this category.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="T"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Template
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    A template is a chunk of HTML that Angular uses to render a [view](#view) with
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    the support and continuing guidance of an Angular [Directive](#directive),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    most notably a [Component](#component).
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    We write templates in a special [Template Syntax](./template-syntax.html).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-31 13:05:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  ## Template Expression
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    An expression in a JavaScript-like syntax that Angular evaluates within
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    a [data binding](#data-binding).  Learn how to write template expressions
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    in the [Template Syntax](./template-syntax.html#template-expressions) chapter.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Transpile
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    The process of transforming code written in one form of JavaScript
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    (e.g., TypeScript) into another form of JavaScript  (e.g., [ES5](#es5)).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								 :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## TypeScript
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    A version of JavaScript that supports most [ECMAScript 2015](#ecmascript=2015)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    language features and many features that may arrive in future versions
							 
						 
					
						
							
								
									
										
										
										
											2015-10-31 13:05:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    of JavaScript such as [Decorators](#decorator).
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    TypeScript is also noteable for its optional typing system which gives
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    us compile-time type-checking and strong tooling support (e.g. "intellisense",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    code completion, refactoring, and intelligent search). Many code editors
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    and IDEs support TypeScript either natively or with plugins.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    TypeScript is the preferred language for Angular 2 development although
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    we are welcome to write in other JavaScript dialects such as [ES5](#es5).
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Angular 2 itself is written in TypeScript.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Learn more about TypeScript on its [website](http://www.typescriptlang.org/).
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="U"></a>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								<a id="V"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## View
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    A view is a portion of the screen that displays information and responds
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    to user actions such as clicks, mouse moves, and keystrokes.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Angular renders a view under the control of one or more [Directives](#directive),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    especially  [Component](#component) directives and their companion [Templates](#template).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    The Component plays such a prominent role that we often
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    find it convenient to refer to a component as a view.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Views often contain other views and any view might be loaded and unloaded
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    dynamically as the user navigates through the application, typically
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    under the control of a [router](#rounter).
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-24 11:53:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								<a id="W"></a>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								<a id="X"></a>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								<a id="Y"></a>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								<a id="Z"></a>
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Zone
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Zones are a mechanism for encapsulating and intercepting
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    a JavaScript application's asynchronous activity.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    The browser DOM and JavaScript have a limited number
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    of asynchronous activities, activities such as DOM events (e.g., clicks),
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    [promises](#promise), and
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    [XHR](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest)
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    calls to remote servers.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Zones intercept all of these activities and give a "zone client" the opportunity
							 
						 
					
						
							
								
									
										
										
										
											2016-01-02 16:47:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    to take action before and after the async activity completes.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 14:51:15 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Angular runs our application in a zone where it can respond to
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    asynchronous events by checking for data changes and updating
							 
						 
					
						
							
								
									
										
										
										
											2015-10-31 19:29:02 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    the information it displays via [data binding](#data-binding).
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Learn more about zones in this
							 
						 
					
						
							
								
									
										
										
										
											2016-01-02 16:47:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    [Brian Ford video](https://www.youtube.com/watch?v=3IqtmUscE_U).