Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disabling a div in angularjs using ng-disabled

Tags:

angularjs

I wanted to disable a div section using ng-disabled, but it dint work. I've also tried using fieldset in place of div. ng-disabled seems not working.

Below is the view part:

<div ng-disabled="model.disableDate">
    <div>Date</div>
    <div ion-datetime-picker ng-model="model.timeEntryDate" ng-change="onTimeEntryDateChange()" date="true" time="false" monday-first="true" am-pm="true">{{model.timeEntryDate|| "Select" | date: "dd/MM/yyyy"}} <i class="icon ion-ios-calendar-outline"></i> </div>
</div>

This is the controller part:

if ($scope.model.pageState === condition) {
    $scope.model.disableDate = true;
}

Any way this calender is being popped even on the disabling condition.

like image 894
Chris Avatar asked Dec 03 '22 12:12

Chris


2 Answers

You can't disable DIV. Disable work with button and input types only. You can try with css. Use ng-class.

<div ng-class="{ 'div-disabled': model.disableDate}"> // give condition here as per your scenario

.div-disabled
{
  pointer-events: none;
  opacity: 0.5;
  background: #CCC;
}
like image 58
Manikandan Velayutham Avatar answered Dec 23 '22 11:12

Manikandan Velayutham


You can create an attribute directive to disable any div. See below:

  var app = angular.module("myApp", []);
        app.directive("disableSection", function() {
            return {
                restrict : "A",
                 link:function(scope,element,attr,ctrl){                   
                        element.css({
                          cursor :"not-allowed",
                          opacity: "0.5",
                          background: "#CCC"
                        });
                    }
            };
        });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
  <div disable-section>This is disabled div</div>
</body>
like image 43
Ankush Jain Avatar answered Dec 23 '22 10:12

Ankush Jain