Search code examples
mysqlangulartypescriptloopback

I Don't know how to delete values using angular7


I'm using angular7 with loopback API. I want make delete code in tables. Can you suggest me.

But I tried some code it's not working. I have attached my code here..

file.component.html

    <td><button class="btn btn-success" (click)="deleteUser(user)"> Delete</button></td>

file.component.ts

   deleteUser(user: User): void {
this.apiService.deleteUser(user.id);
 };

api.service.ts

deleteUser(id: number): Observable<ApiResponse> {
return this.http.delete<ApiResponse>(this.baseUrl + id);
}

Also give me all the operation codes like update delete


Solution

  • First thing, you didn't subscribe, so the request didn't go out.

    deleteUser(user: User): void {
       this.apiService.deleteUser(user.id).subscribe();
    };