I am developing an angular project using Angular version 7. I have a table that shows some json objects. In each json object, I added 2 buttons, which I show conditionally when each one is selected.
What I mean is, when I click the Edit button, I want the No Edit button to be shown and vice versa ONLY FOR THE ROW I PRESSED THE BUTTON. But what is happening is that when I click the Edit button for a specific row, then all other buttons for the other rows change.
How can I do this?
myapp.component.html file:
<table>
<thead>
<tr>
<th scope="col" translate>Name</th>
<th scope="col" translate>Description</th>
</tr>
</thead>
<tbody>
<tr *ngFor=" let product of products">
<td>{{product.name}}</td>
<td>{{datasource.description}}</td>
<td>
<button *ngIf="allowEdit" (click)="edit(product)">
Edit
</button>
<button *ngIf="allowNoEdit" (click)="noEdit(product)">
No Edit
</button>
</td>
</tr>
</tbody>
</table>
myapp.component.ts file:
allowEdit: boolean = true;
allowNoEdit: boolean = false;
edit(product) {
this.allowEdit= !this.allowEdit;
this.allowNoEdit= !this.allowNoEdit;
}
noEdit(product) {
this.allowEdit= !this.allowEdit;
this.allowNoEdit= !this.allowNoEdit;
}