Angular 6 http.delete请求不起作用 [英] Angular 6 http.delete request not working

查看:50
本文介绍了Angular 6 http.delete请求不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法让我的删除请求正常工作.我已经完成了所有的get请求,但是现在我被困在delete上,似乎无法将其包裹住.

I cant seem to get my delete request to work. I have finished all of the get requests but now I'm stuck on delete and can't seem to wrap my head around it.

console.log的URL始终是正确的,并且通过Postman可以正常执行删除请求.

The console.log'd URL is always correct and the delete request works fine via Postman.

有什么想法吗?

HTML

<button class="button button3" (click)="delTicket()"><span class="fa fa-trash"></span></button>

TS

delTicket(){
    this.id = this.route.snapshot.params.id;
    this.ticketService.deleteTicket(this.id);
}

服务

deleteTicket(id): Observable<Ticket[]>{
    console.log(this.apiUrl + id);
    return this.http.delete<Ticket[]>(this.apiUrl + id);
}

推荐答案

您需要在组件内部调用 subscribe(),否则请求将不会被调用

You need to call subscribe() inside your component, otherwise request wont get invoked

delTicket(){
    this.id = this.route.snapshot.params.id;
    this.ticketService.deleteTicket(this.id).subscribe((data)=>{
         console.log("success");
    });
}

这篇关于Angular 6 http.delete请求不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆