Home > database >  How to disable button in angular securely?
How to disable button in angular securely?

Time:07-19

I just found out that you can go to the html and just remove the disable="true" from the button and enable it back again

So my question is if there is a way to securely disable buttons so that no one can enable them back again using the html.

CodePudding user response:

You cannot "safely" disable stuff on the client side. User can modify not only HTML, but the javascript as well, so even if there would be "secure" ways to disable buttons, users could still check what javascript will run and run it.

CodePudding user response:

If its a button , you may apply [disabled]="disable" and prevent them from running the function bound to it.

<button [disabled]="checkIfDisabled" (click)="handleClick()">Click me</button>
public handleClick() {
   if(!checkIfDisabled) {
     ... do stuffs
   }
}

With this you can prevent someone from running the function even they took out the disabled property on the button element

  • Related