Skip to content

Instantly share code, notes, and snippets.

@pgiemza
Created June 17, 2017 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgiemza/fefc13eb1f7f5455c579eba81e4609e5 to your computer and use it in GitHub Desktop.
Save pgiemza/fefc13eb1f7f5455c579eba81e4609e5 to your computer and use it in GitHub Desktop.
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