Skip to content

Commit 3794b91

Browse files
Fazendo método http delete e seu component de manipulação
1 parent be1fa3e commit 3794b91

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/app/courses/course-list.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ <h2>Course List</h2>
3636
<app-star [rating]="course.rating"></app-star>
3737
</td>
3838
<td>
39-
<a [routerLink]="['/courses/info', course.id]" class="btn btn-primary">Edit</a>
39+
<a [routerLink]="['/courses/info', course.id]" class="btn btn-primary mr-2">Edit</a>
40+
<button (click)="deleteById(course.id)" class="btn btn-danger">Delete</button>
4041
</td>
4142
</tr>
4243
</tbody>

src/app/courses/course-list.component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ export class CourseListComponent implements OnInit {
1818
this.retriveAll();
1919
}
2020

21+
deleteById(courseId: number): void {
22+
this.courseService.deleteById(courseId).subscribe({
23+
next: (msg) => {
24+
console.log('Deleted with sucess');
25+
this.retriveAll();
26+
},
27+
error: (msg) => {
28+
console.log('Deleted with error: ', msg);
29+
},
30+
});
31+
}
32+
2133
retriveAll(): void {
2234
this.courseService.retriveAll().subscribe({
2335
next: (courses) => {

src/app/courses/course.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export class CourseService {
2929
return this.httCliente.post<Course>(`${this.courseUrl}`, course);
3030
}
3131
}
32+
33+
deleteById(id: number): Observable<any> {
34+
return this.httCliente.delete<any>(`${this.courseUrl}/${id}`);
35+
}
3236
}
3337

3438
var COURSES: Course[] = [

0 commit comments

Comments
 (0)