| 
									
										
										
										
											2016-02-06 17:02:44 -05:00
										 |  |  | // #docplaster
 | 
					
						
							|  |  |  | // #docregion
 | 
					
						
							|  |  |  | // #docregion imports
 | 
					
						
							|  |  |  | import 'package:angular2/core.dart'; | 
					
						
							| 
									
										
										
										
											2016-03-03 22:50:42 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import 'app_config.dart'; | 
					
						
							| 
									
										
										
										
											2016-02-06 17:02:44 -05:00
										 |  |  | import 'car/car_component.dart'; | 
					
						
							|  |  |  | import 'heroes/heroes_component.dart'; | 
					
						
							|  |  |  | import 'logger_service.dart'; | 
					
						
							|  |  |  | import 'user_service.dart'; | 
					
						
							| 
									
										
										
										
											2016-03-03 22:50:42 -08:00
										 |  |  | //PENDING: check whether we intend to hide injector_component.dart & providers_component.dart; if so, change docregion name?
 | 
					
						
							| 
									
										
										
										
											2016-02-06 17:02:44 -05:00
										 |  |  | // #enddocregion imports
 | 
					
						
							|  |  |  | import 'injector_component.dart'; | 
					
						
							|  |  |  | import 'providers_component.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component( | 
					
						
							|  |  |  |     selector: 'my-app', | 
					
						
							|  |  |  |     template: '''
 | 
					
						
							| 
									
										
										
										
											2016-03-03 22:50:42 -08:00
										 |  |  |       <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: const [ | 
					
						
							|  |  |  |       CarComponent, | 
					
						
							|  |  |  |       HeroesComponent, | 
					
						
							|  |  |  |       InjectorComponent, | 
					
						
							|  |  |  |       ProvidersComponent | 
					
						
							|  |  |  |     ], | 
					
						
							| 
									
										
										
										
											2016-02-06 17:02:44 -05:00
										 |  |  | // #docregion providers
 | 
					
						
							| 
									
										
										
										
											2016-03-03 22:50:42 -08:00
										 |  |  |     providers: const [ | 
					
						
							|  |  |  |       Logger, | 
					
						
							|  |  |  |       UserService, | 
					
						
							|  |  |  |       const Provider(AppConfig, useValue: config1)] | 
					
						
							| 
									
										
										
										
											2016-02-06 17:02:44 -05:00
										 |  |  | // #enddocregion providers
 | 
					
						
							| 
									
										
										
										
											2016-03-03 22:50:42 -08:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2016-02-06 17:02:44 -05:00
										 |  |  | class AppComponent { | 
					
						
							| 
									
										
										
										
											2016-03-03 22:50:42 -08:00
										 |  |  |   final UserService _userService; | 
					
						
							|  |  |  |   final String title; | 
					
						
							| 
									
										
										
										
											2016-02-06 17:02:44 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   //#docregion ctor
 | 
					
						
							| 
									
										
										
										
											2016-03-03 22:50:42 -08:00
										 |  |  |   AppComponent(AppConfig config, this._userService) | 
					
						
							|  |  |  |       : title = config.title; | 
					
						
							| 
									
										
										
										
											2016-02-06 17:02:44 -05:00
										 |  |  |   // #enddocregion ctor
 | 
					
						
							| 
									
										
										
										
											2016-03-03 22:50:42 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-06 17:02:44 -05:00
										 |  |  |   bool get isAuthorized { | 
					
						
							|  |  |  |     return user.isAuthorized; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void nextUser() { | 
					
						
							|  |  |  |     _userService.getNewUser(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   User get user { | 
					
						
							|  |  |  |     return _userService.user; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-03 22:50:42 -08:00
										 |  |  |   String get userInfo => 'Current user, ${user.name}, is' | 
					
						
							|  |  |  |       '${isAuthorized ? "" : " not"} authorized. '; | 
					
						
							| 
									
										
										
										
											2016-02-06 17:02:44 -05:00
										 |  |  | } | 
					
						
							|  |  |  | // #enddocregion
 |