herlanS_ 5 years ago
parent
commit
d18fc8ee13

+ 4 - 0
src/app/dtcservice/user.service.ts

@@ -31,4 +31,8 @@ export class UserService {
     return this.http.get<User>(url);
   }
 
+  deleteUser(id:number):Observable<any>{
+    return this.http.delete(`${this.apihost}/user/${id}`);
+  }
+
 }

+ 2 - 0
src/app/module/module-user/user-list/user-list.component.html

@@ -4,5 +4,7 @@
         <h5>{{user.username}}</h5>
        Fullname : {{user.fullname}}
        <br /><button routerLink="/user/detail/{{user.id}}" class="pure-button pure-button-primary">Detail</button>
+       &nbsp;
+       <button (click)="deleteUser(user.id)" class="pure-button pure-button-primary">Delete</button>
     </li>
 </ul>

+ 6 - 0
src/app/module/module-user/user-list/user-list.component.ts

@@ -21,4 +21,10 @@ export class UserListComponent implements OnInit {
     this.getUsers()
   }
 
+  deleteUser(id:number):void{    
+    this.userService.deleteUser(id).subscribe(()=>
+      this.users = this.users.filter(u => u.id !== id)
+    )
+  }
+
 }