File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed
Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff 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 >
Original file line number Diff line number Diff 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 ) => {
Original file line number Diff line number Diff 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
3438var COURSES : Course [ ] = [
You can’t perform that action at this time.
0 commit comments