0

I have code:

export class Test {

constructor(private http: Http) {}

logResponse(): Observable<any> {
  return this.http.get('http://google.com')
    .do(data => console.log("All: " +  JSON.stringify(data)));
  }
}

But still, nothing gets printed out to the console sadly. I am just starting with Rxjs, so sorry for the lame question. Why is it not logged ? I have all the http and imports needed, no exception just nothing gets printed. I trigger it on a button press.

1
  • Looks like you need a promise Commented Jun 9, 2016 at 20:17

1 Answer 1

4

You have to add first subscribe to activate that. This observable is cold (hot vs cold observables).

So in your case:

logResponse(): Observable<any> {
  return this.http.get('http://google.com')
    .do(data => console.log("All: " +  JSON.stringify(data)))
    .subscribe(data => console.log("All from subscribe: " +  JSON.stringify(data)));
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.