Home > Net >  Cannot show and hide button in angular
Cannot show and hide button in angular

Time:11-17

I have this isData variable declared in my ts file

isData:boolean=false;

i have this button on my component

<button
        
        type="button"
        (click)="save()"
        *ngIf="isData===false"
      >
        Save
    </button>

isData is false but button is not shown i have tried with isData=='false' this also same issue.

Any solution Thanks

CodePudding user response:

This should do the trick:

*ngIf="!isData"

CodePudding user response:

Maybe your button is not shown because its container is hidden? Could you provide the code for the button container?

CodePudding user response:

If I understood correctly, you wish to enable the button when there isData is false.

However, ngIf needs to be true for it to enable the button.

@nate-kumar's answer should work assuming isData is false..

CodePudding user response:

If somehow ngIf is not working in angular, you may try hidden property with the inverse condition

<button
    
    type="button"
    (click)="save()"
    [hidden]="!isData"
  >
    Save
</button>

I hope this will help you for the problem.

CodePudding user response:

*ngIf="isData==false ? true : false"

It means when isData is false then show this button otherwise hide it. Use == equal instead of ===

  • Related