| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  | // #docplaster
 | 
					
						
							|  |  |  | // #docregion
 | 
					
						
							|  |  |  | // #docregion imports
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { Component, Inject, provide } from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { CarComponent }      from './car/car.component'; | 
					
						
							|  |  |  | import { HeroesComponent }   from './heroes/heroes.component'; | 
					
						
							| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { APP_CONFIG, | 
					
						
							|  |  |  |         Config, CONFIG }    from './app.config'; | 
					
						
							|  |  |  | import { Logger }            from './logger.service'; | 
					
						
							| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { User, UserService } from './user.service'; | 
					
						
							| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  | // #enddocregion imports
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { InjectorComponent } from './injector.component'; | 
					
						
							|  |  |  | import { TestComponent }     from './test.component'; | 
					
						
							|  |  |  | import { ProvidersComponent } from './providers.component'; | 
					
						
							| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'my-app', | 
					
						
							|  |  |  |   template:  `
 | 
					
						
							|  |  |  |     <h1>{{title}}</h1> | 
					
						
							|  |  |  |     <my-car></my-car> | 
					
						
							|  |  |  |     <my-injectors></my-injectors> | 
					
						
							|  |  |  |     <my-tests></my-tests> | 
					
						
							|  |  |  |     <h2>User</h2> | 
					
						
							|  |  |  |     <p id="user"> | 
					
						
							|  |  |  |       {{userInfo}} | 
					
						
							|  |  |  |       <button (click)='nextUser()'>Next User</button> | 
					
						
							|  |  |  |     <p> | 
					
						
							|  |  |  |     <my-heroes id="authorized" *ngIf="isAuthorized"></my-heroes> | 
					
						
							|  |  |  |     <my-heroes id="unauthorized" *ngIf="!isAuthorized"></my-heroes> | 
					
						
							|  |  |  |   `,
 | 
					
						
							|  |  |  |   directives:[CarComponent, HeroesComponent, | 
					
						
							|  |  |  |               InjectorComponent, TestComponent, ProvidersComponent], | 
					
						
							|  |  |  | // #docregion providers
 | 
					
						
							|  |  |  |   providers: [ | 
					
						
							|  |  |  |     Logger, | 
					
						
							|  |  |  |     UserService, | 
					
						
							|  |  |  |     provide(APP_CONFIG, {useValue: CONFIG}) | 
					
						
							|  |  |  |   ] | 
					
						
							|  |  |  | // #enddocregion providers
 | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | export class AppComponent { | 
					
						
							|  |  |  |   title:string; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   //#docregion ctor
 | 
					
						
							|  |  |  |   constructor( | 
					
						
							|  |  |  |     @Inject(APP_CONFIG) config:Config, | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |     private userService: UserService) { | 
					
						
							| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     this.title = config.title; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   // #enddocregion ctor
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   get isAuthorized() { return this.user.isAuthorized;} | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |   nextUser()         { this.userService.getNewUser(); } | 
					
						
							|  |  |  |   get user()         { return this.userService.user; } | 
					
						
							| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   get userInfo()     { | 
					
						
							|  |  |  |     return `Current user, ${this.user.name}, is `+ | 
					
						
							|  |  |  |            `${this.isAuthorized ? '' : 'not'} authorized. `; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | // #enddocregion
 |