2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# The Ahead-of-Time (AOT) compiler
  
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								An Angular application consists mainly of components and their HTML templates. Because the components and templates provided by Angular cannot be understood by the browser directly, Angular applications require a compilation process before they can run in a browser.
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The Angular Ahead-of-Time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase _before_  the browser downloads and runs that code. Compiling your application during the build process provides a faster rendering in the browser.
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This guide explains how to specify metadata and apply available compiler options to compile your applications efficiently using the AOT compiler.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  class = "alert is-helpful"  
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-16 14:20:56 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < a  href = "https://www.youtube.com/watch?v=kW9cJsvcsGo" > Watch compiler author Tobias Bosch explain the Angular compiler< / a >  at AngularConnect 2016.
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{@a  overview}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Angular compilation
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Angular offers two ways to compile your application:
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								1.  **_Just-in-Time_ (JIT)** , which compiles your app in the browser at runtime. 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								1.  **_Ahead-of-Time_ (AOT)** , which compiles your app at build time. 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								JIT compilation is the default when you run the [`ng build` ](cli/build ) (build only) or [`ng serve` ](cli/serve )  (build and serve locally) CLI commands:
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example  language = "sh"  class = "code-shell" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ng build
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ng serve
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / code-example >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  compile}
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-16 14:20:56 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For AOT compilation, include the `--aot`  option with the `ng build`  or `ng serve`  command:
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example  language = "sh"  class = "code-shell" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ng build --aot
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ng serve --aot
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / code-example >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-07-19 15:00:08 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< div  class = "alert is-helpful" >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The `ng build`  command with the `--prod`  meta-flag (`ng build --prod` ) compiles with AOT by default.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-16 14:20:56 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								See the [CLI command reference ](cli ) and [Building and serving Angular apps ](guide/build ) for more information.
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  why-aot}
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Why compile with AOT?
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*Faster rendering*
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								With AOT, the browser downloads a pre-compiled version of the application.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The browser loads executable code so it can render the application immediately, without waiting to compile the app first.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*Fewer asynchronous requests*
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler _inlines_  external HTML templates and CSS style sheets within the application JavaScript,
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								eliminating separate ajax requests for those source files.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*Smaller Angular framework download size*
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								There's no need to download the Angular compiler if the app is already compiled.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The compiler is roughly half of Angular itself, so omitting it dramatically reduces the application payload.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*Detect template errors earlier*
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The AOT compiler detects and reports template binding errors during the build step
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								before users can see them.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*Better security*
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								AOT compiles HTML templates and components into JavaScript files long before they are served to the client.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								With no templates to read and no risky client-side HTML or JavaScript evaluation,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								there are fewer opportunities for injection attacks.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Controlling app compilation
  
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								When you use the Angular AOT compiler, you can control your app compilation in two ways:
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:58:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								*  By [specifying Angular metadata ](#metadata-aot ), as described below. 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:58:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								*  By providing options in the `tsconfig.json`  [TypeScript configuration file ](guide/typescript-configuration ). See [Angular compiler options ](guide/angular-compiler-options ). 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  metadata-aot}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Specifying Angular metadata
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Angular metadata tells Angular how to construct instances of your application classes and interact with them at runtime.
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The Angular **AOT compiler**  extracts **metadata**  to interpret the parts of the application that Angular is supposed to manage.
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can specify the metadata with **decorators**  such as `@Component()`  and `@Input()`  or implicitly in the constructor declarations of these decorated classes.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								In the following example, the `@Component()`  metadata object and the class constructor tell Angular how to create and display an instance of `TypicalComponent` .
							 
						 
					
						
							
								
									
										
										
										
											2017-03-30 20:04:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  selector: 'app-typical',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  template: '< div > A typical component for {{data.name}}< / div > '
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								)}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class TypicalComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  @Input () data: TypicalData;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  constructor(private someService: SomeService) { ... }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The Angular compiler extracts the metadata _once_  and generates a _factory_  for `TypicalComponent` .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								When it needs to create a `TypicalComponent`  instance, Angular calls the factory, which produces a new visual element, bound to a new instance of the component class with its injected dependency.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Metadata restrictions
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You write metadata in a _subset_  of TypeScript that must conform to the following general constraints:
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								1.  Limit [expression syntax ](#expression-syntax ) to the supported subset of JavaScript. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								2.  Only reference exported symbols after [code folding ](#folding ). 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								3.  Only call [functions supported ](#supported-functions ) by the compiler. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								4.  Decorated and data-bound class members must be public. 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The next sections elaborate on these points.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## How AOT works
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								It helps to think of the AOT compiler as having two phases: a code analysis phase in which it simply records a representation of the source; and a code generation phase in which the compiler's `StaticReflector`  handles the interpretation as well as places restrictions on what it interprets.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Phase 1: analysis
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The TypeScript compiler does some of the analytic work of the first phase. It emits the `.d.ts`  _type definition files_  with type information that the AOT compiler needs to generate application code.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								At the same time, the AOT **_collector_**  analyzes the metadata recorded in the Angular decorators and outputs metadata information in ** `.metadata.json` ** files, one per `.d.ts`  file.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can think of `.metadata.json`  as a diagram of the overall structure of a decorator's metadata, represented as an [abstract syntax tree (AST) ](https://en.wikipedia.org/wiki/Abstract_syntax_tree ).
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-07-19 15:00:08 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< div  class = "alert is-helpful" >  
						 
					
						
							
								
									
										
										
										
											2017-03-30 20:04:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-11 04:35:19 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Angular's [schema.ts ](https://github.com/angular/angular/blob/master/packages/compiler-cli/src/metadata/schema.ts )
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								describes the JSON format as a collection of TypeScript interfaces.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{@a  expression-syntax}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Expression syntax
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The _collector_  only understands a subset of JavaScript.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Define metadata objects with the following limited syntax:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  td, th {vertical-align: top}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< table >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < th > Syntax< / th > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < th > Example< / th > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Literal object < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > {cherry: true, apple: true, mincemeat: false}< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Literal array  < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > ['cherries', 'flour', 'sugar']< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Spread in literal array< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > ['apples', 'flour', ...the_rest]< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Calls< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > bake(ingredients)< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > New< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > new Oven()< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Property access< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > pie.slice< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Array index< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > ingredients[0]< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Identity reference< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > Component< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > A template string< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > `pie is ${multiplier} times better than cake` </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Literal string< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > pi< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Literal number< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > 3.14153265< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Literal boolean< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > true< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Literal null< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > null< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Supported prefix operator < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > !cake< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Supported binary operator < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > a+b< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Conditional operator< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > a ? b : c< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Parentheses< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > (a+b)< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / table >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								If an expression uses unsupported syntax, the _collector_  writes an error node to the `.metadata.json`  file. The compiler later reports the error if it needs that
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								piece of metadata to generate the application code.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-07-19 15:00:08 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< div  class = "alert is-helpful" >  
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 If you want `ngc`  to report syntax errors immediately rather than produce a `.metadata.json`  file with errors, set the `strictMetadataEmit`  option in `tsconfig` .
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "angularCompilerOptions": {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   "strictMetadataEmit" : true
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 ```
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Angular libraries have this option to ensure that all Angular `.metadata.json`  files are clean and it is a best practice to do the same when building your own libraries.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  function-expression}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{@a  arrow-functions}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### No arrow functions
  
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The AOT compiler does not support [function expressions ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								and [arrow functions ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions ), also called _lambda_  functions.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Consider the following component decorator:
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [{provide: server, useFactory: () => new Server()}]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The AOT _collector_  does not support the arrow function, `() => new Server()` , in a metadata expression.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								It generates an error node in place of the function.
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								When the compiler later interprets this node, it reports an error that invites you to turn the arrow function into an _exported function_ .
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can fix the error by converting to this:
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								export function serverFactory() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return new Server();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [{provide: server, useFactory: serverFactory}]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-03-10 17:14:58 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Beginning in version 5, the compiler automatically performs this rewriting while emitting the `.js`  file.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  function-calls}
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Limited function calls
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The _collector_  can represent a function call or object creation with `new`  as long as the syntax is valid. The _collector_  only cares about proper syntax.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								But beware. The compiler may later refuse to generate a call to a _particular_  function or creation of a _particular_  object.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The compiler only supports calls to a small set of functions and will use `new`  for only a few designated classes. These functions and classes are in a table of [below ](#supported-functions ).
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Folding
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{@a  exported-symbols}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The compiler can only resolve references to **_exported_**  symbols.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Fortunately, the _collector_  enables limited use of non-exported symbols through _folding_ .
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The _collector_  may be able to evaluate an expression during collection and record the result in the `.metadata.json`  instead of the original expression.
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For example, the _collector_  can evaluate the expression `1 + 2 + 3 + 4`  and replace it with the result, `10` .
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This process is called _folding_ . An expression that can be reduced in this manner is _foldable_ .
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  var-declaration}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The collector can evaluate references to
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								module-local `const`  declarations and initialized `var`  and `let`  declarations, effectively removing them from the `.metadata.json`  file.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Consider the following component definition:
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const template = '< div > {{hero.name}}< / div > ';
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  selector: 'app-hero',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  template: template
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class HeroComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  @Input () hero: Hero;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler could not refer to the `template`  constant because it isn't exported.
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								But the _collector_  can _fold_  the `template`  constant into the metadata definition by inlining its contents.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The effect is the same as if you had written:
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  selector: 'app-hero',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  template: '< div > {{hero.name}}< / div > '
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class HeroComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  @Input () hero: Hero;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								There is no longer a reference to `template`  and, therefore, nothing to trouble the compiler when it later interprets the _collector's_  output in `.metadata.json` .
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can take this example a step further by including the `template`  constant in another expression:
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const template = '< div > {{hero.name}}< / div > ';
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  selector: 'app-hero',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  template: template + '< div > {{hero.title}}< / div > '
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class HeroComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  @Input () hero: Hero;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The _collector_  reduces this expression to its equivalent _folded_  string:
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`'<div>{{hero.name}}</div><div>{{hero.title}}</div>'` . 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#### Foldable syntax
  
						 
					
						
							
								
									
										
										
										
											2017-03-30 20:04:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The following table describes which expressions the _collector_  can and cannot fold:
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  td, th {vertical-align: top}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< table >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < th > Syntax< / th > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < th > Foldable< / th > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Literal object < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Yes< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Literal array  < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Yes< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Spread in literal array< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > no< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Calls< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > no< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > New< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > no< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Property access< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > yes, if target is foldable< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Array index< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >  yes, if target and index are foldable< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Identity reference< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > yes, if it is a reference to a local< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > A template with no substitutions< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > yes< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > A template with substitutions< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > yes, if the substitutions are foldable< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Literal string< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > yes< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Literal number< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > yes< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Literal boolean< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > yes< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Literal null< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > yes< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Supported prefix operator < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > yes, if operand is foldable< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Supported binary operator < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > yes, if both left and right are foldable< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Conditional operator< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > yes, if condition is foldable < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > Parentheses< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > yes, if the expression is foldable< / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / table >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								If an expression is not foldable, the collector writes it to `.metadata.json`  as an [AST ](https://en.wikipedia.org/wiki/Abstract_syntax_tree ) for the compiler to resolve.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Phase 2: code generation
  
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The _collector_  makes no attempt to understand the metadata that it collects and outputs to `.metadata.json` . It represents the metadata as best it can and records errors when it detects a metadata syntax violation.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								It's the compiler's job to interpret the `.metadata.json`  in the code generation phase.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler understands all syntax forms that the _collector_  supports, but it may reject _syntactically_  correct metadata if the _semantics_  violate compiler rules.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler can only reference _exported symbols_ .
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 23:44:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Decorated component class members must be public. You cannot make an `@Input()`  property private or protected.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Data bound properties must also be public.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// BAD CODE - title is private
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  selector: 'app-root',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  template: '< h1 > {{title}}< / h1 > '
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class AppComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  private title = 'My App'; // Bad
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  supported-functions}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Most importantly, the compiler only generates code to create instances of certain classes, support certain decorators, and call certain functions from the following lists.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### New instances
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler only allows metadata that create instances of the class `InjectionToken`  from `@angular/core` .
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Annotations/Decorators
  
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler only supports metadata for these Angular decorators.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-26 15:11:02 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  td, th {vertical-align: top}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< table >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < th > Decorator< / th > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < th > Module< / th > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > Attribute< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > Component< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > ContentChild< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > ContentChildren< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > Directive< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > Host< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > HostBinding< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > HostListner< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > Inject< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > Injectable< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > Input< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > NgModule< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > Optional< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > Output< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > Pipe< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > Self< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > SkipSelf< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td > < code > ViewChild< / code > < / td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < td >< code > @angular/core </ code ></ td > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / tr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / table > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Macro-functions and macro-static methods
  
						 
					
						
							
								
									
										
										
										
											2017-04-19 11:43:46 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler also supports _macros_  in the form of functions or static
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								methods that return an expression.
							 
						 
					
						
							
								
									
										
										
										
											2017-03-30 20:04:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For example, consider the following function:
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								export function wrapInArray< T > (value: T): T[] {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return [value];
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can call the `wrapInArray`  in a metadata definition because it returns the value of an expression that conforms to the compiler's restrictive JavaScript subset.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You might use  `wrapInArray()`  like this:
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@NgModule ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  declarations: wrapInArray(TypicalComponent)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class TypicalModule {}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler treats this usage as if you had written:
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@NgModule ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  declarations: [TypicalComponent]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class TypicalModule {}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The collector is simplistic in its determination of what qualifies as a macro
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function; it can only contain a single `return`  statement.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The Angular [`RouterModule` ](api/router/RouterModule ) exports two macro static methods, `forRoot`  and `forChild` , to help declare root and child routes.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Review the [source code ](https://github.com/angular/angular/blob/master/packages/router/src/router_module.ts#L139 "RouterModule.forRoot source code" )
							 
						 
					
						
							
								
									
										
										
										
											2017-07-04 10:58:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								for these methods to see how macros can simplify configuration of complex [NgModules ](guide/ngmodules ).
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  metadata-rewriting}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Metadata rewriting
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler treats object literals containing the fields `useClass` , `useValue` , `useFactory` , and `data`  specially. The compiler converts the expression initializing one of these fields into an exported variable, which replaces the expression. This process of rewriting these expressions removes all the restrictions on what can be in them because
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								the compiler doesn't need to know the expression's value— it just needs to be able to generate a reference to the value.
							 
						 
					
						
							
								
									
										
										
										
											2017-03-30 20:04:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You might write something like:
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class TypicalServer {
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@NgModule ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [{provide: SERVER, useFactory: () => TypicalServer}]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class TypicalModule {}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Without rewriting, this would be invalid because lambdas are not supported and `TypicalServer`  is not exported.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								To allow this, the compiler automatically rewrites this to something like:
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```typescript
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class TypicalServer {
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								export const ɵ0 = () => new TypicalServer();
							 
						 
					
						
							
								
									
										
										
										
											2017-08-11 16:40:25 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@NgModule ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [{provide: SERVER, useFactory: ɵ0}]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class TypicalModule {}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-03-30 20:04:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This allows the compiler to generate a reference to `ɵ0`  in the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								factory without having to know what the value of `ɵ0`  contains.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler does the rewriting during the emit of the `.js`  file. This doesn't rewrite the `.d.ts`  file, however, so TypeScript doesn't recognize it as being an export. Thus, it does not pollute the ES module's exported API.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Metadata errors
  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The following are metadata errors you may encounter, with explanations and suggested corrections.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[Expression form not supported ](#expression-form-not-supported )< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[Reference to a local (non-exported) symbol ](#reference-to-a-local-symbol )< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[Only initialized variables and constants ](#only-initialized-variables )< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[Reference to a non-exported class ](#reference-to-a-non-exported-class )< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[Reference to a non-exported function ](#reference-to-a-non-exported-function )< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[Function calls are not supported ](#function-calls-not-supported )< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[Destructured variable or constant not supported ](#destructured-variable-not-supported )< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[Could not resolve type ](#could-not-resolve-type )< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[Name expected ](#name-expected )< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[Unsupported enum member name ](#unsupported-enum-member-name )< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[Tagged template expressions are not supported ](#tagged-template-expressions-not-supported )< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[Symbol reference expected ](#symbol-reference-expected )< br > 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< hr >  
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< h3  class = "no-toc" > Expression form not supported< / h3 >  
						 
					
						
							
								
									
										
										
										
											2017-03-30 20:04:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-03-10 17:14:58 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler encountered an expression it didn't understand while evaluating Angular metadata.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Language features outside of the compiler's [restricted expression syntax ](#expression-syntax )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								can produce this error, as seen in the following example:
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ERROR
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class Fooish { ... }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const prop = typeof Fooish; // typeof is not valid in metadata
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // bracket notation is not valid in metadata
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  { provide: 'token', useValue: { [prop]: 'value' } };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can use `typeof`  and bracket notation in normal application code.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								You just can't use those features within expressions that define Angular metadata.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Avoid this error by sticking to the compiler's [restricted expression syntax ](#expression-syntax )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								when writing Angular metadata
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								and be wary of new or unusual TypeScript features.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< hr >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  reference-to-a-local-symbol}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< h3  class = "no-toc" > Reference to a local (non-exported) symbol< / h3 >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< div  class = "alert is-helpful" >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								_Reference to a local (non-exported) symbol 'symbol name'. Consider exporting the symbol._
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler encountered a referenced to a locally defined symbol that either wasn't exported or wasn't initialized.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Here's a `provider`  example of the problem.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ERROR
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								let foo: number; // neither exported nor initialized
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  selector: 'my-component',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  template: ... ,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: Foo, useValue: foo }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class MyComponent {}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The compiler generates the component factory, which includes the `useValue`  provider code, in a separate module. _That_  factory module can't reach back to _this_  source module to access the local (non-exported) `foo`  variable.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You could fix the problem by initializing `foo` .
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								let foo = 42; // initialized
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler will [fold ](#folding ) the expression into the provider as if you had written this.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: Foo, useValue: 42 }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Alternatively, you can fix it by exporting `foo`  with the expectation that `foo`  will be assigned at runtime when you actually know its value.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// CORRECTED
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export let foo: number; // exported
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  selector: 'my-component',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  template: ... ,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: Foo, useValue: foo }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class MyComponent {}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Adding `export`  often works for variables referenced in metadata such as `providers`  and `animations`  because the compiler can generate _references_  to the exported variables in these expressions. It doesn't need the _values_  of those variables.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Adding `export`  doesn't work when the compiler needs the _actual value_ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								in order to generate code.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								For example, it doesn't work for the `template`  property.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ERROR
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export let someTemplate: string; // exported but not initialized
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  selector: 'my-component',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  template: someTemplate
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class MyComponent {}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler needs the value of the `template`  property _right now_  to generate the component factory.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The variable reference alone is insufficient.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Prefixing the declaration with `export`  merely produces a new error, "[`Only initialized variables and constants can be referenced` ](#only-initialized-variables )".
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< hr >  
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  only-initialized-variables}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< h3  class = "no-toc" > Only initialized variables and constants< / h3 >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< div  class = "alert is-helpful" >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								_Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler._
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-10 16:51:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler found a reference to an exported variable or static field that wasn't initialized.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								It needs the value of that variable to generate code.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The following example tries to set the component's `template`  property to the value of
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								the exported `someTemplate`  variable which is declared but _unassigned_ .
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ERROR
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export let someTemplate: string;
							 
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  selector: 'my-component',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  template: someTemplate
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class MyComponent {}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								You'd also get this error if you imported `someTemplate`  from some other module and neglected to initialize it there.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ERROR - not initialized there either
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import { someTemplate } from './config';
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  selector: 'my-component',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  template: someTemplate
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class MyComponent {}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler cannot wait until runtime to get the template information.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								It must statically derive the value of the `someTemplate`  variable from the source code
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								so that it can generate the component factory, which includes
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								instructions for building the element based on the template.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								To correct this error, provide the initial value of the variable in an initializer clause _on the same line_ .
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// CORRECTED
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export let someTemplate = '< h1 > Greetings from Angular< / h1 > ';
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  selector: 'my-component',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  template: someTemplate
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class MyComponent {}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< hr >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< h3  class = "no-toc" > Reference to a non-exported class< / h3 >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  class = "alert is-helpful" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								_Reference to a non-exported class < class  name > . Consider exporting the class._
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-10 16:51:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Metadata referenced a class that wasn't exported.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For example, you may have defined a class and used it as an injection token in a providers array
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								but neglected to export that class.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ERROR
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								abstract class MyStrategy { }
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: MyStrategy, useValue: ... }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Angular generates a class factory in a separate module and that
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								factory [can only access exported classes ](#exported-symbols ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								To correct this error, export the referenced class.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// CORRECTED
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export abstract class MyStrategy { }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: MyStrategy, useValue: ... }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< hr >  
						 
					
						
							
								
									
										
										
										
											2017-08-10 00:20:25 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< h3  class = "no-toc" > Reference to a non-exported function< / h3 >  
						 
					
						
							
								
									
										
										
										
											2017-03-30 20:04:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Metadata referenced a function that wasn't exported.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								For example, you may have set a providers `useFactory`  property to a locally defined function that you neglected to export.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ERROR
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function myStrategy() { ... }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: MyStrategy, useFactory: myStrategy }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Angular generates a class factory in a separate module and that
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								factory [can only access exported functions ](#exported-symbols ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								To correct this error, export the function.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// CORRECTED
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export function myStrategy() { ... }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: MyStrategy, useFactory: myStrategy }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< hr >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{@a  function-calls-not-supported}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< h3  class = "no-toc" > Function calls are not supported< / h3 >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  class = "alert is-helpful" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								_Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function._
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The compiler does not currently support [function expressions or lambda functions ](#function-expression ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								For example, you cannot set a provider's `useFactory`  to an anonymous function or arrow function like this.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ERROR
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: MyStrategy, useFactory: function() { ... } },
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: OtherStrategy, useFactory: () => { ... } }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								You also get this error if you call a function or method in a provider's `useValue` .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ERROR
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import { calculateValue } from './utilities';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: SomeValue, useValue: calculateValue() }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								To correct this error, export a function from the module and refer to the function in a `useFactory`  provider instead.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example >  
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// CORRECTED
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import { calculateValue } from './utilities';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export function myStrategy() { ... }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export function otherStrategy() { ... }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export function someValueFactory() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return calculateValue();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: MyStrategy, useFactory: myStrategy },
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: OtherStrategy, useFactory: otherStrategy },
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: SomeValue, useFactory: someValueFactory }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< / code-example >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< hr >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{@a  destructured-variable-not-supported}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< h3  class = "no-toc" > Destructured variable or constant not supported< / h3 >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  class = "alert is-helpful" >  
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								_Referencing an exported destructured variable or constant is not supported by the template compiler. Consider simplifying this to avoid destructuring._
							 
						 
					
						
							
								
									
										
										
										
											2017-04-19 15:57:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-10 16:51:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
									
										
										
										
											2017-03-27 16:08:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The compiler does not support references to variables assigned by [destructuring ](https://www.typescriptlang.org/docs/handbook/variable-declarations.html#destructuring ).
							 
						 
					
						
							
								
									
										
										
										
											2017-03-30 20:04:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For example, you cannot write something like this:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example >  
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// ERROR
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import { configuration } from './configuration';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// destructured assignment to foo and bar
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const {foo, bar} = configuration;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {provide: Foo, useValue: foo},
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {provide: Bar, useValue: bar},
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / code-example >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								To correct this error, refer to non-destructured values.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example >  
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// CORRECTED
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import { configuration } from './configuration';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {provide: Foo, useValue: configuration.foo},
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {provide: Bar, useValue: configuration.bar},
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< / code-example >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< hr >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< h3  class = "no-toc" > Could not resolve type< / h3 >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The compiler encountered a type and can't determine which module exports that type.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This can happen if you refer to an ambient type.
							 
						 
					
						
							
								
									
										
										
										
											2018-04-24 15:15:45 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For example, the `Window`  type is an ambient type declared in the global `.d.ts`  file.
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 01:57:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You'll get an error if you reference it in the component constructor,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								which the compiler must statically analyze.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ERROR
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Component ({ }) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class MyComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  constructor (private win: Window) { ... }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-04-24 15:15:45 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								TypeScript understands ambient types so you don't import them.
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The Angular compiler does not understand a type that you neglect to export or import.
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								In this case, the compiler doesn't understand how to inject something with the `Window`  token.
							 
						 
					
						
							
								
									
										
										
										
											2017-03-30 20:04:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Do not refer to ambient types in metadata expressions.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-24 15:15:45 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								If you must inject an instance of an ambient type,
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								you can finesse the problem in four steps:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-24 15:15:45 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								1.  Create an injection token for an instance of the ambient type. 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								1.  Create a factory function that returns that instance. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								1.  Add a `useFactory`  provider with that factory function. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								1.  Use `@Inject`  to inject the instance. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Here's an illustrative example.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example >  
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// CORRECTED
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import { Inject } from '@angular/core ';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export const WINDOW = new InjectionToken('Window');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export function _window() { return window; }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Component ({ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: WINDOW, useFactory: _window }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class MyComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  constructor (@Inject (WINDOW) private win: Window) { ... }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< / code-example >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The `Window`  type in the constructor is no longer a problem for the compiler because it
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								uses the `@Inject(WINDOW)`  to generate the injection code.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Angular does something similar with the `DOCUMENT`  token so you can inject the browser's `document`  object (or an abstraction of it, depending upon the platform in which the application runs).
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example >  
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import { Inject }   from '@angular/core ';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import { DOCUMENT } from '@angular/platform -browser';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Component ({ ... }) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export class MyComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  constructor (@Inject (DOCUMENT) private doc: Document) { ... }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / code-example >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< hr >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< h3  class = "no-toc" > Name expected< / h3 >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The compiler expected a name in an expression it was evaluating.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This can happen if you use a number as a property name as in the following example.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ERROR
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								provider: [{ provide: Foo, useValue: { 0: 'test' } }]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Change the name of the property to something non-numeric.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// CORRECTED
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								provider: [{ provide: Foo, useValue: { '0': 'test' } }]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< hr >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< h3  class = "no-toc" > Unsupported enum member name< / h3 >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Angular couldn't determine the value of the [enum member ](https://www.typescriptlang.org/docs/handbook/enums.html )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								that you referenced in metadata.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The compiler can understand simple enum values but not complex values such as those derived from computed properties.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example >  
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// ERROR
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								enum Colors {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Red = 1,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  White,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Blue = "Blue".length // computed
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  providers: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: BaseColor,   useValue: Colors.White } // ok
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: DangerColor, useValue: Colors.Red }   // ok
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { provide: StrongColor, useValue: Colors.Blue }  // bad
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ...
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:09:39 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< / code-example >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-02 14:34:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Avoid referring to enums with complicated initializers or computed properties.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< hr >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{@a  tagged-template-expressions-not-supported}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< h3  class = "no-toc" > Tagged template expressions are not supported< / h3 >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  class = "alert is-helpful" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								_Tagged template expressions are not supported in metadata._
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The compiler encountered a JavaScript ES2015 [tagged template expression ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals ) such as,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ERROR
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const expression = 'funky';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const raw = String.raw`A tagged template ${expression} string` ;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 template: '< div > ' + raw + '< / div > '
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[`String.raw()` ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								is a _tag function_  native to JavaScript ES2015.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The AOT compiler does not support tagged template expressions; avoid them in metadata expressions.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< hr >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< h3  class = "no-toc" > Symbol reference expected< / h3 >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The compiler expected a reference to a symbol at the location specified in the error message.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This error can occur if you use an expression in the `extends`  clause of a class.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								<!-- 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Chuck: After reviewing your PR comment I'm still at a loss. See [comment there ](https://github.com/angular/angular/pull/17712#discussion_r132025495 ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-->
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  binding-expression-validation}
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ## Phase 3: binding expression validation
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  In the validation phase, the Angular template compiler uses the TypeScript compiler to validate the
							 
						 
					
						
							
								
									
										
										
										
											2018-03-10 17:14:58 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  binding expressions in templates. Enable this phase explicitly by adding the compiler
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  option `"fullTemplateTypeCheck"`  in the `"angularCompilerOptions"`  of the project's `tsconfig.json`  (see
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:58:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  [Angular Compiler Options ](guide/angular-compiler-options )).
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Template validation produces error messages when a type error is detected in a template binding
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  expression, similar to how type errors are reported by the TypeScript compiler against code in a `.ts` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  file.
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  For example, consider the following component:
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ```typescript
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  @Component ({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    selector: 'my-component',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    template: '{{person.addresss.street}}'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  class MyComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    person?: Person;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ```
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  This will produce the following error:
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  my.component.ts.MyComponent.html(1,1): : Property 'addresss' does not exist on type 'Person'. Did you mean 'address'?
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ```
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  The file name reported in the error message, `my.component.ts.MyComponent.html` , is a synthetic file
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  generated by the template compiler that holds contents of the `MyComponent`  class template.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Compiler never writes this file to disk. The line and column numbers are relative to the template string
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  in the `@Component`  annotation of the class, `MyComponent`  in this case. If a component uses
							 
						 
					
						
							
								
									
										
										
										
											2018-03-10 17:14:58 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  `templateUrl`  instead of `template` , the errors are reported in the HTML file referenced by the
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  `templateUrl`  instead of a synthetic file.
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  The error location is the beginning of the text node that contains the interpolation expression with
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  the error. If the error is in an attribute binding such as `[value]="person.address.street"` , the error
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  location is the location of the attribute that contains the error.
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  The validation uses the TypeScript type checker and the options supplied to the TypeScript compiler to control
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  how detailed the type validation is. For example, if the `strictTypeChecks`  is specified, the error  ```my.component.ts.MyComponent.html(1,1): : Object is possibly 'undefined'` `` is reported as well as the above error message.
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ### Type narrowing
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  The expression used in an `ngIf`  directive is used to narrow type unions in the Angular
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  template compiler, the same way the `if`  expression does in TypeScript. For example, to avoid
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  `Object is possibly 'undefined'`  error in the template above, modify it to only emit the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  interpolation if the value of `person`  is initialized as shown below:
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ```typescript
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  @Component ({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    selector: 'my-component',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    template: '< span  * ngIf = "person" >  {{person.addresss.street}} < / span > '
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  class MyComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    person?: Person;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ```
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Using `*ngIf`  allows the TypeScript compiler to infer that the `person`  used in the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  binding expression will never be `undefined` .
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  #### Custom `ngIf`  like directives
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Directives that behave like `*ngIf`  can declare that they want the same treatment by including
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  a static member marker that is a signal to the template compiler to treat them
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  like `*ngIf` . This static member for `*ngIf`  is:
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ```typescript
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    public static ngIfUseIfTypeGuard: void;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ```
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  This declares that the input property `ngIf`  of the `NgIf`  directive should be treated as a
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  guard to the use of its template, implying that the template will only be instantiated if
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  the `ngIf`  input property is true.
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ### Non-null type assertion operator
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Use the [non-null type assertion operator ](guide/template-syntax#non-null-assertion-operator )
							 
						 
					
						
							
								
									
										
										
										
											2018-10-03 00:24:36 +07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  to suppress the `Object is possibly 'undefined'`  error when it is inconvenient to use
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  `*ngIf`  or when some constraint in the component ensures that the expression is always
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  non-null when the binding expression is interpolated.
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  In the following example, the `person`  and `address`  properties are always set together,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  implying that `address`  is always non-null if `person`  is non-null. There is no convenient
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  way to describe this constraint to TypeScript and the template compiler, but the error
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  is suppressed in the example by using `address!.street` .
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ```typescript
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  @Component ({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    selector: 'my-component',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    template: '< span  * ngIf = "person" >  {{person.name}} lives on {{address!.street}} < / span > '
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  class MyComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    person?: Person;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    address?: Address;
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    setData(person: Person, address: Address) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      this.person = person;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      this.address = address;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ```
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  The non-null assertion operator should be used sparingly as refactoring of the component
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  might break this constraint.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  In this example it is recommended to include the checking of `address` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  in the `*ngIf` as shown below:
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ```typescript
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  @Component ({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    selector: 'my-component',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    template: '< span  * ngIf = "person && address" >  {{person.name}} lives on {{address.street}} < / span > '
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  class MyComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    person?: Person;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    address?: Address;
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    setData(person: Person, address: Address) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      this.person = person;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      this.address = address;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ```
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ### Disabling type checking using `$any()` 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Disable checking of a binding expression by surrounding the expression
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  in a call to the [`$any()` cast pseudo-function ](guide/template-syntax ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  The compiler treats it as a cast to the `any`  type just like in TypeScript when a `<any>` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  or `as any`  cast is used.
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  In the following example, the error `Property addresss does not exist`  is suppressed
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  by casting `person`  to the `any`  type.
							 
						 
					
						
							
								
									
										
										
										
											2018-01-17 14:43:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ```typescript
							 
						 
					
						
							
								
									
										
										
										
											2018-01-05 08:10:35 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  @Component ({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    selector: 'my-component',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    template: '{{$any(person).addresss.street}}'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  class MyComponent {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    person?: Person;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ```
							 
						 
					
						
							
								
									
										
										
										
											2018-02-21 10:09:16 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-11 09:38:28 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{@a  tsconfig-extends}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Configuration inheritance with extends
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Similar to TypeScript Compiler, Angular Compiler also supports `extends`  in the `tsconfig.json`  on `angularCompilerOptions` . A tsconfig file can inherit configurations from another file using the `extends`  property.
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 The `extends`  is a top level property parallel to `compilerOptions`  and `angularCompilerOptions` .
							 
						 
					
						
							
								
									
										
										
										
											2018-09-11 09:38:28 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 The configuration from the base file are loaded first, then overridden by those in the inheriting config file.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 Example:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```json
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "extends": "../tsconfig.base.json",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "compilerOptions": {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "experimentalDecorators": true,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  },
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "angularCompilerOptions": {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "fullTemplateTypeCheck": true,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "preserveWhitespaces": true,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 More information about tsconfig extends can be found in the [TypeScript Handbook ](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html ).