6

I tried lots and search numbers of time but I didnt get any solution to disable click on div element. Already question has been asked but they are saying not possible on divs and I want to know only, is there any ways to disable div in angular2

<div>(click)="isDisabled ? $event.stopPropagation() : myClickHandler($event); isDisabled ? false : null"
   [class.isDisabled]="isDisabled"></div>

And the old answer not clearly about disabling divs and pointer-events:none is not supported in old version browser also it become editable from network tab

8
  • Possible duplicate of How to disable clicking inside div Commented May 8, 2018 at 13:38
  • 1
    How is div even enabled? You have to actually programmatically make clicks on div even do anything, what would you disable? Commented May 8, 2018 at 13:39
  • Yeh, I checked but the answer not supporting in old browser Commented May 8, 2018 at 13:40
  • Could you post some of your code so we can see what you have tried? Commented May 8, 2018 at 13:40
  • @ritaj , I need to restrict divs to be clicked till my request has been completed Commented May 8, 2018 at 13:55

2 Answers 2

13

You can use css:

pointer-events:none

Or maybe could do something like:

<div (click)="false; $event.stopPropagation();"> </div>

There are several ways of preventing a click, depends on what you need

Sign up to request clarification or add additional context in comments.

1 Comment

I just need to restrict the click event on divs thats it, but without css
2

The straightforward answer here will be just not to render the function if the element should be disabled. Something like this:

<div (click)="shouldBeDisabled ? null : callYourFunctionHere()"></div>

But a better solution will be to put this condition into your function itself

HTML

<div (click)="callYourFunctionHere()"></div>

TS

const callYourFunctionHere = () => {
  if (this.shouldBeDisabled) return
  
  //if statement above is false your general logic will be rendered
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.