Skip to content

Instantly share code, notes, and snippets.

@Rome-H
Last active June 8, 2017 09:23
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 Rome-H/e62659cd3be690d81efc3ee72367e56b to your computer and use it in GitHub Desktop.
Save Rome-H/e62659cd3be690d81efc3ee72367e56b to your computer and use it in GitHub Desktop.
components design: rescue-bot-example
@Component({
selector: 'rescue-bot-detail',
templateUrl: './rescue-bot-detail.component.html'
})
export class RescueBotDetailComponent implements OnInit {
user$: Observable<User>;
bot$: Observable<Bot>;
completedRescues$: Observable<completedRescue[]>;
constructor(
private route: ActivatedRoute,
private botsService: BotsService,
private newsletterService: NewsletterService,
private userService:UserService
) {}
ngOnInit() {
this.user$ = this.userService.user$;
this.bot$ = this.route.paramMap
.map(params => params.get('id'))
.switchMap(botId => this.botsService.findBotById(botId));
this.completedRescues$ = this.bot$
.switchMap(bot => this.botsService.findRescuesForBot(bot.id));
}
onSubscribe(email:string) {
this.newsletterService.subscribeToNewsletter(email)
.subscribe(
() => alert('Subscription successful ...'),
console.error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment