javascript - How to delete a particular row from table in Angular 2 by clicking delete button from that row -
i trying delete particular row clicking button row in loop,but deleting rows of table.
here html code:
<table id="mytable" class="table table-bordred table-striped"> <tbody id="del"> <tr *ngfor="let cart of modaldata"> <td> <div style="display:inline-flex;"> <div style="margin-left:10px;"> <p class="font_weight" style="font-size:13px;">{{cart.examname}}</p> <p>{{cart.categoryname}}|{{cart.companyname}}</p> </div> </div> </td> <td> <div style="margin-top: 32px;"> <p class="font_weight" style="font-size:13px;"></p> <span class="font_weight" style="font-size: 13px;"> {{cart.amount| currency :'usd':'true'}} </span> </div> </td> <td> <div style="margin-top: 19px;"> <button class="button_transparent" (click)="delete(cart)"> delete </button> </div> </td> </tr> <tr> </tr> </tbody> </table>
here component:
public loaddata() { let transaction = new transactionalinformation(); this.mycartservice.getexamorderforcart() .subscribe(response => this.getdataonsuccess(response), response => this.getdataonerror(response)); } getdataonsuccess(response) { this.modaldata = response.items; }
this delete method:
public delete(response) { this.mycartservice.updateexamorder(response) .subscribe(response => this.getdataonsuccessfordelete(response), response => this.getdataonerrorfordelete(response)); }
please me do, how delete 1 row table?
you can add index
in *ngfor :
<tr *ngfor="let cart of modaldata;let = index">
then, pass index in method:
<button class="button_transparent" (click)="delete(i)"> delete </button>
and finally:
delete(i){ this.modaldata.splice(i,1); }
Comments
Post a Comment