import { Http } from '@angular/http'; // Inject Http service constructor(private http: Http) {} // Send DELETE request to delete a user by ID deleteUser(id: number) { return this.http.delete(`https://example.com/users/${id}`); }
import { Http, Headers } from '@angular/http'; // Inject Http service constructor(private http: Http) {} // Send DELETE request to remove an item from a shopping cart removeFromCart(item: string, sessionId: string) { // Set headers const headers = new Headers(); headers.append('Content-Type', 'application/json'); headers.append('sessionId', sessionId); // Send DELETE request with headers and body return this.http.delete(`https://example.com/cart/items/${item}`, { headers }); }In both examples, the Http.delete method is used to send a DELETE request to a server. The first example deletes a user by ID, and the second example removes an item from a shopping cart. The HttpHeaders object is used to set headers for the request. The `@angular/http` package library is used for this code.