How to delete per index, i have a parameter and remove button i tried to put my parameter inside my remove button but it wont work how to fix that?
deleteRowFiles(rowIndex: number){
this.getListFileName();
if(this.uploadAttachments.length > 1){
Swal.fire({
title: 'Are you sure?',
text: 'You will not be able to recover this data!',
icon: 'error',
showCancelButton: true,
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel'
}).then((result) => {
if(result.value){
this.uploadAttachments.removeAt(rowIndex);
this.microSvc.deleteFile(this.iData.transactionType,this.uploadedFiles).pipe(
return this.refreshPage();
})
}else if (result.dismiss === Swal.DismissReason.cancel){}
})
}
HTML
<td (click)="deleteRowFiles(i)">
<i ></i>
</td>
CodePudding user response:
There is no removeAt in javascript you can use splice instead
this.uploadAttachments.splice(rowIndex,1);
CodePudding user response:
I always replace the array reference with a new array where the item to be removed has been filtered out
this.uploadAttachments = this.uploadAttachments.filter((_, i) => i !== rowIndex);