This is the deleteUser function of user service which call the backend server
deleteUser(id:number)
{
return this.http.delete(`${this.Url}/${id}`)
}
and this is the userComponent which display the list of users on a grid.
I want to delete user by clicking on 'supprimer'
@Component({
template: <ul *ngFor=" let x of users">
<li>{{x.id}}</li>
<li>{{x.firstName}}</li>
<li>{{x.lastname}}</li>
<li>{{x.username}}</li>
<li>{{x.password}}</li>
<li><a (click)="deleteItem(x.id)">supprimer</a></li>
</ul>
})
export class UserListComponent implements OnInit {
private users: User[];
constructor(private userService: UserService ,private router:Router) { }
ngOnInit() {
his.userService.getAllUsers().subscribe(data => {this.users = data })
}
deleteItem(id:number) {
this.userService.deleteUser(id).subscribe( );
}
}