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

179
Views
Operación de eliminación de tabla angular

En mi aplicación, tengo una lista donde el usuario puede agregar y eliminar elementos. Mi problema es que cuando hago clic en un elemento (puede estar en el medio, al final, etc.), elimina el primer elemento de la lista. Y cuando actualizo la página, puedo ver los elementos 'eliminados' anteriormente. Como si no hubiera borrado nada. Aquí está mi código. ¿Qué tiene de malo y cómo debo solucionarlo?

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

Parece que no pasa index al método deleteWorkItem .

Debe declarar una variable de plantilla dentro de *ngFor de la siguiente manera:

 <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!