如果标题措辞不当,我深表歉意。在我的角度代码库中,我可以看到两个不同的放置请求:
public Save() {
const types: string[] = this.getTypes.getCurrentTypes();
this.userTypeService
.updateTypes(this.userID, groups)
.subscribe(() => {
showToast("success", "User types Updated.");
});
}
其中 updateTypes 是一个发出简单 httpPut 请求的函数。
这和使用的重复函数有什么区别
.subscribe(
showToast("success", "user types updated");
)
基本上,订阅中 () => 的功能是什么?另外,有没有什么好的方法可以使用这种方式从调用中捕获错误?
编辑:我想通了,下面的答案对我有用:
public Save() {
const types: string[] = this.getTypes.getCurrentTypes();
this.userTypeService
.updateTypes(this.userID, groups)
.subscribe(() => {
result => showToast("success", "User types Updated.");
error => showToast("error", "Error");
});
}
牧羊人nacy
相关分类