I need to show a toast after an observable is plete, how i can do it, my code is:
thismerceCtrl.UpdateCategories(this.toSave).subscribe(data => {
}, error => {
this.mainFunction.showError(error)
}),
plete => {
this.mainFunction.showToast(this.localization.message_ok)
}
I tried to do like this:
thismerceCtrl.UpdateCategories(this.toSave).subscribe(data => {
}, error => {
this.mainFunction.showError(error)
}),
() => {
this.mainFunction.showToast(this.localization.message_ok)
}
but it doesn't work
I need to show a toast after an observable is plete, how i can do it, my code is:
this.merceCtrl.UpdateCategories(this.toSave).subscribe(data => {
}, error => {
this.mainFunction.showError(error)
}),
plete => {
this.mainFunction.showToast(this.localization.message_ok)
}
I tried to do like this:
this.merceCtrl.UpdateCategories(this.toSave).subscribe(data => {
}, error => {
this.mainFunction.showError(error)
}),
() => {
this.mainFunction.showToast(this.localization.message_ok)
}
but it doesn't work
Share Improve this question edited Apr 12, 2019 at 8:45 jo_va 14k3 gold badges25 silver badges49 bronze badges asked Apr 12, 2019 at 8:29 To_MarsTo_Mars 1254 silver badges12 bronze badges3 Answers
Reset to default 7You have to pass the plete
handler as the third argument to subscribe.
In your code, simply move the closing parenthesis to the end.
Change this code:
this.merceCtrl.UpdateCategories(this.toSave).subscribe(data => {
}, error => {
this.mainFunction.showError(error)
}), // <===== Remove this parenthesis
() => {
this.mainFunction.showToast(this.localization.message_ok)
}; // <====== It should be here
To this:
this.merceCtrl.UpdateCategories(this.toSave).subscribe(
data => {
// next handler body
}, error => {
this.mainFunction.showError(error)
}, () => {
this.mainFunction.showToast(this.localization.message_ok)
}
);
You can give object parameter to subscribe()
function:
this.merceCtrl.UpdateCategories(this.toSave).subscribe({
next: value => { ... },
error: err => { ... },
plete: () => { ... }
});
You can try to use finally method
this.merceCtrl.UpdateCategories(this.toSave).finally(() => {
// plete
}).subscribe((data) => {
// success
}, (error) => {
// error
});
Source: https://github./angular/angular/issues/7865#issuement-204408637