【发布时间】:2021-08-05 07:28:36
【问题描述】:
目前,我正在学习 Angular 中的 http 请求模块。 我的问题是为什么错误没有发生并且即使请求 id delete 不在数据列表中仍然被删除。
deletePost(x) {
this.s.deleteInfo(33).subscribe(res => {
console.log(res);
let index = this.post.indexOf(x);
this.post.splice(index, 1);
},(error:Response)=>{
if(error.status ==404){
alert("Expected Error!");
console.log("hello")
}
});
我们可以看到控制台上只显示了 6 个数据,但我仍然可以删除 id 为 33 的数据
【问题讨论】:
-
您能分享一下您的 this.s 服务吗?并且可能共享网络错误。 (要检查网络错误,您必须使用“网络”选项卡在开发工具中查找它们)每当您使用后端通信时,请尝试打开此选项卡以查看您的后端回答是什么。
标签: angular httpclient rest