I have code with subscribe
inside subscribe
:
this.http.post('/update1', newData).subscribe(
(response) => {
const r = response.json;
const id = r['id'];
this.http.post('/update2?id=' + id, newData).subscribe(
() => {
this.http.post('/update3?id=' + id, newData).subscribe(
() => {
console.log('success');
},
() => {
// revert changes made to update2
this.http.post('/update2', previousValues).subscribe();
// revert changes made to update1
this.http.post('/update1', previousValues).subscribe();
});
},
() => {
// revert changes made to update1
this.http.post('/update1', previousValues).subscribe();
}
);
},
(error) => {
console.log(error);
}
);
How can I optimize it in RxJS 5?