Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subscribe method on http.get observable: what is the third argument?

I use subscribe method on observable (result of http.get) in Angular 2 final version. While the first argument of the subscribe method is function which gets data from backend, the second one is function which is executed on error (like status http code 404), I don't understand meaning of the third argunent/function.

In hope it is executed always when the request has ended (with either success or error), I remove/stop loading indicator in it, but the third function is not called on error.

like image 727
Leos Ondra Avatar asked Jan 14 '17 12:01

Leos Ondra


1 Answers

The third argument of every sequence is the complete handler. It is invoked with no params and just notifies the sequence finished.

Observable.from([1,3]).subscribe(
  (v => console.log('value: ', v)),
  (e => console.log('error: ', e)),
  (() => console.log('the sequence completed!'))

would print:

value: 1

value: 2

the sequence completed

like image 93
Meir Avatar answered Sep 27 '22 22:09

Meir