2016-02-02 08:39:34 -05:00
|
|
|
// #docregion
|
|
|
|
import {Component} from 'angular2/core';
|
|
|
|
import {AstronautComponent} from './astronaut.component';
|
|
|
|
import {MissionService} from './mission.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'mission-control',
|
|
|
|
template: `
|
|
|
|
<h2>Mission Control</h2>
|
|
|
|
<button (click)="announce()">Announce mission</button>
|
|
|
|
<my-astronaut *ngFor="#astronaut of astronauts"
|
|
|
|
[astronaut]="astronaut">
|
|
|
|
</my-astronaut>
|
2016-03-07 14:50:14 -05:00
|
|
|
<h3>History</h3>
|
2016-02-02 08:39:34 -05:00
|
|
|
<ul>
|
|
|
|
<li *ngFor="#event of history">{{event}}</li>
|
|
|
|
</ul>
|
|
|
|
`,
|
|
|
|
directives: [AstronautComponent],
|
|
|
|
providers: [MissionService]
|
|
|
|
})
|
|
|
|
export class MissionControlComponent {
|
|
|
|
astronauts = ['Lovell', 'Swigert', 'Haise']
|
|
|
|
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`);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// #enddocregion
|