| 
									
										
										
										
											2016-02-02 14:39:34 +01:00
										 |  |  | // #docregion
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { Component }          from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { MissionService }     from './mission.service'; | 
					
						
							| 
									
										
										
										
											2016-02-02 14:39:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'mission-control', | 
					
						
							|  |  |  |   template: `
 | 
					
						
							|  |  |  |     <h2>Mission Control</h2> | 
					
						
							|  |  |  |     <button (click)="announce()">Announce mission</button> | 
					
						
							| 
									
										
										
										
											2016-04-29 01:36:35 +01:00
										 |  |  |     <my-astronaut *ngFor="let astronaut of astronauts" | 
					
						
							| 
									
										
										
										
											2016-02-02 14:39:34 +01:00
										 |  |  |       [astronaut]="astronaut"> | 
					
						
							|  |  |  |     </my-astronaut> | 
					
						
							| 
									
										
										
										
											2016-03-07 11:50:14 -08:00
										 |  |  |     <h3>History</h3> | 
					
						
							| 
									
										
										
										
											2016-02-02 14:39:34 +01:00
										 |  |  |     <ul> | 
					
						
							| 
									
										
										
										
											2016-04-29 01:36:35 +01:00
										 |  |  |       <li *ngFor="let event of history">{{event}}</li> | 
					
						
							| 
									
										
										
										
											2016-02-02 14:39:34 +01:00
										 |  |  |     </ul> | 
					
						
							|  |  |  |   `,
 | 
					
						
							|  |  |  |   providers: [MissionService] | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | export class MissionControlComponent { | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |   astronauts = ['Lovell', 'Swigert', 'Haise']; | 
					
						
							| 
									
										
										
										
											2016-02-02 14:39:34 +01:00
										 |  |  |   history: string[] = []; | 
					
						
							|  |  |  |   missions = ['Fly to the moon!', | 
					
						
							|  |  |  |               'Fly to mars!', | 
					
						
							|  |  |  |               'Fly to Vegas!']; | 
					
						
							|  |  |  |   nextMission = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   constructor(private missionService: MissionService) { | 
					
						
							|  |  |  |     missionService.missionConfirmed$.subscribe( | 
					
						
							|  |  |  |       astronaut => { | 
					
						
							|  |  |  |         this.history.push(`${astronaut} confirmed the mission`); | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-02-02 14:39:34 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   announce() { | 
					
						
							|  |  |  |     let mission = this.missions[this.nextMission++]; | 
					
						
							|  |  |  |     this.missionService.announceMission(mission); | 
					
						
							|  |  |  |     this.history.push(`Mission "${mission}" announced`); | 
					
						
							|  |  |  |     if (this.nextMission >= this.missions.length) { this.nextMission = 0; } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | // #enddocregion
 |