Skip to content

Instantly share code, notes, and snippets.

@michaelchadwick
Last active June 14, 2017 21:12
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 michaelchadwick/844283521567734284f9935250533d92 to your computer and use it in GitHub Desktop.
Save michaelchadwick/844283521567734284f9935250533d92 to your computer and use it in GitHub Desktop.
angular 2 testing - HomeComponent
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Response } from '@angular/http';
import { Subscription } from 'rxjs/Subscription';
import { DaveService } from '../_services/dave.service';
import { devlog } from '../_helpers/devlog';
@Component({
moduleId: module.id,
templateUrl: './home.component.html',
styleUrls: [ './home.component.css' ]
})
export class HomeComponent implements OnInit, OnDestroy {
private dave: any;
private daveSub: Subscription;
constructor(
private daveService:DaveService,
) { }
ngOnInit() {
this.daveCheckSubscribeObservable();
}
ngOnDestroy() {
this.daveSub.unsubscribe();
}
private daveCheckSubscribeObservable() {
this.daveSub = this.daveService.daveCheckObservable().subscribe(
(daveData: any) => console.log('this.dave post-Obs-call', daveData),
(error) => console.log(error),
() => console.log('daveCheckObservable Completed!')
);
}
private daveCheckObservable() {
devlog('api', 'calling daveService.daveCheckObservable()')
this.dave = this.daveService.daveCheckObservable();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment