Search code examples
angularwebcrudangular13

i need to update the list immediately, once data is deleted in angular 13 component


I am deleting an object from the component, and i need to update the list immediately once the object is deleted, without refreshing the page. component.ts

deleteSource(id: any){
  if(confirm("Are you sure to delete?")){
  console.log(id)
    this.sourcesService.deleteSource(id).subscribe();
    }
    }

service.ts

 deleteSource(id: string): Observable<number>{

     return this.http.delete<number>(this.API_URL +id);
  }

component.html

<button class="btn btn-primary" (click)="deleteSource(source.id)" style="margin-left:5px">

Solution

  • I just had to call get again in the subscribe

    this.sourcesService.deleteSource(id).subscribe(source =>  this.Source());