Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. getResult (): Observable<result[]> {
  2. return this.http.get(this.url)
  3. .map(this.extractData)
  4. .catch(this.handleError);
  5. }
  6.  
  7.  
  8. private extractData(res: Response) {
  9. let body = res.json();
  10.  
  11. // save the data in the service
  12. this.data = body;
  13.  
  14. return body || { };
  15. }
  16.  
  17. getData() {
  18.  
  19. this.data // undefeind !!!!
  20. }
  21.  
  22. this.myService.getResult()
  23. .subscribe(res => {this.data= res;
  24. },
  25. error => {
  26. console.log("error on getData function: " + error);
  27. }
  28. );
  29.  
  30. getResult (): Observable<result[]> {
  31. return this.http.get(this.url)
  32. .map((res)=>this.extractData(res))
  33. .catch((err)=>this.handleError(err));
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement