Description :
In this example of the ng-disabled
directive we have a textbox and upon the textbox we have a link toggle when you click on this it will disable the textbox and the link below the textbox both, click again to make both enable.
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app> <div ng-init="count=1;inactive=false"> <a ng-click="inactive = !inactive" href="">Toggle Active</a> Disable={{inactive}} <br><input type="number" ng-disabled="inactive" ng-model="count"> <br><a ng-click="inactive || (count=count + 1)" href="" style="">click to Increase count</a> {{count}} </div> </body> </html>
Description :
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app> <div> <h4>Click me to toggle: <input type="checkbox" ng-model="isChecked"></h4> <a href="" ng-disabled="isChecked" ng-click="anchorClicks=anchorClicks+1">ANCHOR</a> <button ng-disabled="isChecked" ng-click="buttonClicks=buttonClicks+1">BUTTON</button> <hr /> <p>Anchor Clicks: {{anchorClicks}}</p> <p>Button Clicks: {{buttonClicks}}</p> </div> </body> </html>
Description :
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app> <div> <input ng-disabled="isDisabled" type="button" ng-click="isDisabled=!isDisabled" value="Start" /> <input ng-disabled="!isDisabled" type="button" ng-click="isDisabled=!isDisabled" value="Stop" /> </div> </body> </html>
Description :
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app> <div> Name: <input type="text" ng-model="isDisabled" /> <input type="text" ng-disabled="isDisabled" /> </div> </body> </html>
Description :
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <div ng-controller="controllerName" ng-init="name='[email protected]'"> <label>Enable email field (range should greater then 70): <input type="range" ng-model="rg" ng-change="calculation(rg)"></label><br /> Email:<input ng-disabled="!isEnable" type="email" ng-model="name"> </div> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', function ($scope) { $scope.calculation = function (rg) { $scope.isEnable = rg > 70 ? true : false; } }]); </script> </body> </html>
Description :
In this example of ng-disabled
directive we have a textbox of email type and if you type invalid email in this textbox the submit button will disable and gets enable when you type valid email in the textbox.
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app> <div ng-init="name='[email protected]'"> <form name="myForm"> <label>Email</label> <input type="email" name="name" ng-model="form.name"> <input type="submit" ng-disabled="!myForm.name.$valid"> </form> </div> </body> </html>
Description :
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app> <div> <div> <label>New User?</label> <input type="checkbox" ng-model="isHide" /> </div> <div ng-show="isHide"> <label>Accept Terms and Conditions</label> <input type="radio" value=true name="bool" ng-model="termAndCond" ng-change="isDisabled=!isDisabled" /><label>Yes</label> <input type="radio" value=false name="bool" ng-model="termAndCond" ng-change="isDisabled=!isDisabled" /><label>No</label> </div> <div> <input type="submit" value="Login" ng-disabled="isHide "> <input type="submit" value="Register" ng-show="isHide" ng-disabled="!isDisabled"> </div> </div> </body> </html>
Description :
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <div ng-controller="controllerName" ng-init="isDisabled=false"> <button ng-click="disableClick(isDisabled)" ng-disabled="isDisabled">Disable</button> <button ng-click="disableClick(isDisabled)" ng-show="isDisabled">Enable</button> </div> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', function ($scope) { $scope.disableClick = function (isDisabled) { $scope.isDisabled = !isDisabled; } }]); </script> </body> </html>
Description :
In this example of ng-disable
directive we have two checkboxes one for application form and other for id proof if both are checked then you can activate internet banking means the the button "Active Internet Banking" will only enable if both the checkboxes are checked.
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <div ng-controller="controllerName"> <h3>Application Form <input type="checkbox" ng-model="check" /></h3> <h3>Id Proof<input type="checkbox" ng-model="check2" /> </h3> <br /> <button type="button" ng-disabled="!(check && check2)">Activate Internet Banking</button> </div> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', function ($scope) { $scope.disableClick = function (isDisabled) { $scope.isDisabled = !isDisabled; } }]); </script> </body> </html>