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.
The console.log'd URL is always correct and the delete request works fine via Postman.
Got any ideas?
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);
}
Service
deleteTicket(id): Observable<Ticket[]>{
console.log(this.apiUrl + id);
return this.http.delete<Ticket[]>(this.apiUrl + id);
}
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");
});
}
You must call subscribe() or nothing happens. Just calling ticketService.deleteTicket(this.id) does not initiate the DELETE request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With