5

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

Kamil Naja
  • 5,402
  • 5
  • 30
  • 44
Mohammad Raheem
  • 1,069
  • 1
  • 12
  • 22

2 Answers2

11

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

Lazaro Henrique
  • 327
  • 4
  • 6
0

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
}