Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
Angular Table Delete Operation

In my app, I have a list where the user can add to and delete elements from it. My problem is, when I click an element (it can be in the middle, at the end etc.), it deletes the first element of the list. And when I refresh the page, I can see the previously 'deleted' elements. Like I haven't deleted anything. Here is my code. What's wrong with it and how should I fix it?

HTML:

<button mat-icon-button>
  <mat-icon (click)="deleteWorkItem(row)">block</mat-icon>
</button>

TS:

deleteWorkItem(row: IProduct, index: number) {

  let supplierProduct: ISupplierProduct = {
    Supplier: {
      SupplierId: this.SupplierId
    },
    Product: {
      ProductId: row.ProductId
    }
  };

  this.confirmDialogRef = this._dialog.open(FuseConfirmDialogComponent, {
    disableClose: false
  });
  this.confirmDialogRef.componentInstance.confirmMessage = 'Ürünü silmek istiyor musunuz?';
  this.confirmDialogRef.afterClosed().subscribe(result => {
    if (result) {
      this._service.update('Supplier/DeleteSupplierProduct', supplierProduct).subscribe(response => {
        this._customNotificationService.Show('Ürün silindi', 'Tamam', 2);
      });
      let tempData = this.dataSource.data.slice(0);
      tempData.splice(index, 1);
      this.dataSource = new MatTableDataSource(tempData);
      this.EditIndex = undefined;

      this._products = this.dataSource.data;
      this.ProductChange.emit(this._products);
    }
  });


}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You don't seem to pass index into deleteWorkItem method.

You need to declare a template variable within *ngFor as follows:

<div *ngFor="let row of data; let i = index">
  ...
  <button mat-icon-button>
    <mat-icon (click)="deleteWorkItem(row, i)">block</mat-icon>
  </button>
</div>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!