Search code examples
angularrxjsrxjs6

How does subscribe works for http request?


How does subscribe method work when http client requests data from endpoint?

Does it work as single request http? What if source in endpoint has new data, subscribe shows it after first call?


Solution

  • Every HTTP Observable in Angular completes after the first response (docs). You can test this with the following code:

    http.get('/some/url').subscribe(
      (data) => console.log('Data received:', data),
      (err) => console.log('Error received:', err),
      () => console.log('Observable completed and will not emit any data ever again.')
    );