Angular disable button


Angular disable button On Click – Sometimes we need to disable buttons,links on click event. It is very simple to disable a button in AngularJs. You can use ng-disabled to disable the button, link in AngularJs. Here in this tutorial we are going to explain how you can use ng-disabled to enable and disable button in AngularJs. You can also use our online demo to edit and run the code online.


Angular disable button On Click

Here is a simple example to disable the button in AngularJs-

Angular disable button On Click Example:

<!DOCTYPE html>
<html lang="en">
<head>
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
 <script>
var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope) {
 $scope.disabledFlag = false;
 $scope.disableButton = function() { 
     $scope.disabledFlag = true;
	 };
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController"> 

 <button ng-click='disableButton()' ng-disabled='disabledFlag' >Disable Me</button>
</div> 
</div>
</body>  
</html> 

Try it »

The above example will disable the button if user clicks on the button. If you run the above example it will produce output something like this-

Angular disable button On Click Example


Advertisements

Add Comment

📖 Read More