Angular httpclient delete example

Опубликовано: 30 Июль 2018
на канале: kudvenkat
35,563
175

In this video we will discuss deleting data on the server using Angular HttpClient service. To issue a DELETE request, we use HttpClient service delete() method.

Text version of the video
http://csharp-video-tutorials.blogspo...

Healthy diet is very important for both body and mind. We want to inspire you to cook and eat healthy. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking.
   / @aarvikitchen5572  

Slides
http://csharp-video-tutorials.blogspo...

Angular CRUD Tutorial
   • Angular CRUD tutorial  

Angular CRUD Tutorial Text Articles & Slides
http://csharp-video-tutorials.blogspo...

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenka...

All Dot Net and SQL Server Tutorials in Arabic
   / kudvenkatarabic  

In employee.service.ts file, include the following deleteEmployee() method

baseUrl = 'http://localhost:3000/employees';

deleteEmployee(id: number): Observable[void] {
return this.httpClient.delete[void](`${this.baseUrl}/${id}`)
.pipe(catchError(this.handleError));
}

Code Explanation:
1. deleteEmployee() method takes the ID of the employee to delete as a parameter

2. delete() method does not return anything so we have set the return type to void

3. The URL that is passed as a parameter to the HttpClient delete() method has the ID of the employee to delete

Delete button click event handler is in DisplayEmployeeComponent. So modify deleteEmployee() method in display-employee.component.ts file as shown below.

deleteEmployee() {
this._employeeService.deleteEmployee(this.employee.id).subscribe(
() =] console.log(`Employee with ID = ${this.employee.id} Deleted`),
(err) =] console.log(err)
);
this.notifyDelete.emit(this.employee.id);
}

The success callback function logs the ID of the deleted employee to the console and the error callback function logs the error to the console.


На этой странице сайта вы можете посмотреть видео онлайн Angular httpclient delete example длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь kudvenkat 30 Июль 2018, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 35,563 раз и оно понравилось 175 зрителям. Приятного просмотра!