gpt4 book ai didi

javascript - 检查可观察对象是否完整

转载 作者:太空狗 更新时间:2023-10-29 18:06:25 26 4
gpt4 key购买 nike

我需要在 observable 完成后 toast ,我该怎么做,我的代码是:

this.commerceCtrl.UpdateCategories(this.toSave).subscribe(data => {
}, error => {
this.mainFunction.showError(error)
}),
complete => {
this.mainFunction.showToast(this.localization.message_ok)
}

我试过这样做:

this.commerceCtrl.UpdateCategories(this.toSave).subscribe(data => {
}, error => {
this.mainFunction.showError(error)
}),
() => {
this.mainFunction.showToast(this.localization.message_ok)
}

但是没用

最佳答案

您必须将 complete 处理程序作为第三个参数传递给订阅。

在您的代码中,只需将右括号移至末尾即可。

更改此代码:

this.commerceCtrl.UpdateCategories(this.toSave).subscribe(data => {
}, error => {
this.mainFunction.showError(error)
}), // <===== Remove this parenthesis
() => {
this.mainFunction.showToast(this.localization.message_ok)
}; // <====== It should be here

对此:

this.commerceCtrl.UpdateCategories(this.toSave).subscribe(
data => {
// next handler body
}, error => {
this.mainFunction.showError(error)
}, () => {
this.mainFunction.showToast(this.localization.message_ok)
}
);

关于javascript - 检查可观察对象是否完整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55647485/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com