【发布时间】:2020-09-19 22:57:34
【问题描述】:
如果标题措辞不当,我深表歉意。在我的 Angular 代码库中,我可以看到两个不同的 put 请求:
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");
});
}
【问题讨论】:
标签: javascript angular typescript