Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-disabled is not working on span tag

There is a span tag with glyphicon icon that I want to disable.But ng-disabled is not working, that is the icon is still clickable.

<span ng-disabled="true" class="glyphicon glyphicon-trash" style="font-size:13px;" aria-hidden="true" ng-click="DeleteIpAdress(objIpAdress)" ng-show="objIpAdress.ShowRemoveButton" ng-model="objIpAdress.ShowRemoveButton" title="Delete IP address"></span>

Is anything wrong in the tag?

like image 282
Sunil Garg Avatar asked Nov 17 '15 07:11

Sunil Garg


People also ask

How do I disable a span tag?

This answer could be extended to work globally by simply using css: span[disabled] { pointer-events: none; } . This way you don't need to worry about resetting pointer-events to auto. Or you could use a class like . clicks-disabled { pointer-events: none } .

How do I use NG disable?

Definition and UsageThe ng-disabled directive sets the disabled attribute of a form field (input, select, or textarea). The form field will be disabled if the expression inside the ng-disabled attribute returns true. The ng-disabled directive is necessary to be able to shift the value between true and false .

How do you write if condition in NG-disabled?

Or you can use ng-disabled="condition1 || condition2" , is depend of you logic conditional.

How to enable disable button in AngularJS?

The ng-disabled Directive in AngularJS is used to enable or disable the HTML elements. If the expression inside the ng-disabled attribute returns true then the form field will be disabled or vice versa. It is usually applied on the form field (i.e, input, select, button, etc).


2 Answers

ng-disabled directive works only with input fields and buttons. It does not work with span. Ref: ngDisabled Documentation

You can prevent click action using following code

ng-click="isClickAllowed && DeleteIpAdress(objIpAdress)"
like image 167
Vivek Avatar answered Oct 03 '22 22:10

Vivek


ng-disabled doesn't work on span.So I disabled the click

ng-click="disabledConditionHere || DeleteIpAdress(objIpAdress)"

and then changed the style of span by using class

.disable-span{
    color: #E6E6E6;
    cursor: not-allowed;
}

and used class in span tag

class="disable-span"
like image 20
Sunil Garg Avatar answered Oct 03 '22 22:10

Sunil Garg