Home > Software engineering >  How do I display a button only when a row is selected in Angular
How do I display a button only when a row is selected in Angular

Time:12-16

I have added an extra column to a table for a button to export a row from my table. I’m trying to make it so that button is only displayed for the selected row. (When you haven’t selected any rows there is no button to export the row but when you have selected a row there is a button to export the selected row but only on the row you have selected). I’ve been trying to use ngif but am new to angular so haven’t been able to figure out a solution.

** HTML CODE: **

<button type=“button” class=“btn” (click)=export()>Export</button>

CodePudding user response:

Try the below code:

HTML:

<button *ngIf="selected" type=“button” class=“btn” (click)=export()>Export</button>

TS:

Selected:Boolean=false;

selecteddrow(){
//some condition to for selecting the row.
this.selected=true;

}

  • Related