Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  59] [ 5]  / answers: 1 / hits: 35592  / 8 Years ago, mon, may 16, 2016, 12:00:00

The complete callback does not work as expected. Let me explain:



See this picture, note the complete callback in subscribe method.
This complete function is only called when the observerOrNext is called. When some error happens, the complete is not called. This is right? There are another method to get a callback that always is called when the process finish?



enter



Example:



When success:



this.getData(params)
.subscribe(
successData => {
// this is called
},
error => {
// this is not called. Ok!
},
() => { // when complete
// this is called, ok!
}
);


When error:



this.getData(params)
.subscribe(
successData => {
// this is not called, ok!
},
error => {
// this is called. Ok! Yeah!
},
() => { // when complete
// this is not called, why god??
}
);

More From » angularjs

 Answers
13

I think what you are looking for is the .finally function.




Invokes a specified action after the source observable sequence terminates gracefully or exceptionally. There is an alias called finallyAction for browsers < IE9




Here's an example: finally.md.


[#62144] Saturday, May 14, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aubriechantalr

Total Points: 380
Total Questions: 95
Total Answers: 86

Location: Guadeloupe
Member since Sat, Aug 22, 2020
4 Years ago
;