Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ng-disabled work in div tag? if no, then why?

i have tried using ng-disabled in div tag, but it is not working. does ng-disabled will work on div tags? if yes then how?

<div ng-disabled="true">
 <button>bbb</button>
</div>
like image 748
Balu Avatar asked Oct 07 '14 07:10

Balu


2 Answers

you can use the next directive:

//***********************************// //this directive is ng-disabled directive for all elements and not only for button //***********************************//

app.directive('disabledElement', function () {
    return {
       restrict: 'A', 
        scope: {
            disabled: '@'

        },
        link: function (scope, element, attrs) {

            scope.$parent.$watch(attrs.disabledElement, function (newVal) {

                if (newVal)
                    $(element).css('pointerEvents', 'none');


                else
                    $(element).css('pointerEvents', 'all');


            });

        }

    }
});

and the html:

 <div ng-click="PreviewMobile()" data-disabled-element="toolbar_lock"></div>
like image 79
Lax Avatar answered Sep 26 '22 07:09

Lax


there is a number of elements in HTML that takes the 'disabled' attribute in effect, DIV is not one of them.

you can see what elements take that attribute, here

these elements accept the 'disabled' attr:

  • button
  • input
  • select
  • textarea
  • optgroup
  • option
  • fieldset
like image 40
Nitsan Baleli Avatar answered Sep 23 '22 07:09

Nitsan Baleli