<tbody>
<ng-container *ngFor="let orderdetail of listoforderdetail.listoforders">
<tr>
<td>{{orderdetail.orderId}}</td>
<td>{{orderdetail.ammount | currency:"Rs. "}}</td>
<td>{{datepipe.transform(orderdetail.orderDate,'yyyy-MM-dd HH:mm:ss')}}</td>
<td><button class="btn primary sm" (click)="details=true">Details</button></td>
</tr>
<div *ngIf="details">detail will come here when we click on button on specific ordder</div>
</ng-container>
</tbody>
when I click on detail button of any row of order table ,the detail get rendered but it get rendered below each row as my button and div is in for loop . When I click the button, I want the specific order detail to appear.
It appears below each row, because details is a global variable, which is shared with all the rows. Therefore, once you click on the button, details become true, and the ngif condition becomes true for each row.
You need to have a condition depending on the row itself, so only the selected row become visible
<tbody>
<ng-container *ngFor="let orderdetail of listoforderdetail.listoforders">
<tr>
<td>{{orderdetail.orderId}}</td>
<td>{{orderdetail.ammount | currency:"Rs. "}}</td>
<td>{{datepipe.transform(orderdetail.orderDate,'yyyy-MM-dd HH:mm:ss')}}</td>
<td><button class="btn primary sm" (click)="orderdetail.visible=true">Details</button></td>
</tr>
<div *ngIf="orderdetail.visible">detail will come here when we click on button on specific ordder</div>
</ng-container>
</tbody>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments