Created
June 17, 2017 11:47
-
-
Save pgiemza/fefc13eb1f7f5455c579eba81e4609e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, Input, OnInit } from '@angular/core'; | |
import { MissionService } from './mission.service'; | |
import { DestroyableComponent, componentDestroyed } from 'ng2-rx-destroyable-component'; | |
@DestroyableComponent | |
@Component({ | |
selector: 'my-astronaut', | |
template: ` | |
<p> | |
{{astronaut}}: <strong>{{mission}}</strong> | |
<button | |
(click)="confirm()" | |
[disabled]="!announced || confirmed"> | |
Confirm | |
</button> | |
</p> | |
` | |
}) | |
export class AstronautComponent implements OnInit { | |
@Input() astronaut: string; | |
mission = '<no mission announced>'; | |
confirmed = false; | |
announced = false; | |
constructor(private _missionService: MissionService) { | |
} | |
ngOnInit() { | |
this._missionService.missionAnnounced$ | |
.takeUntil(componentDestroyed(this)) | |
.subscribe( | |
mission => { | |
this.mission = mission; | |
this.announced = true; | |
this.confirmed = false; | |
}); | |
} | |
confirm() { | |
this.confirmed = true; | |
this._missionService.confirmMission(this.astronaut); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment