How can I prevent AngularJS to not click on an HTML button tag that has "disabled" attribute?
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<button type="button" disabled ng-click="something()">No Click Please!</button>
In this case, something() should NOT be called.
To disable a submit button, you just need to add a disabled attribute to the submit button. $("#btnSubmit"). attr("disabled", true); To enable a disabled button, set the disabled attribute to false, or remove the disabled attribute.
Definition and Usage. The 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 .
You can disable a button in angular after it clicked by bounding the button disabled property to a Boolean variable in the component.
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).
You pass an expression that has to be evaluated in the ngClick
directive. If it is not evaluated true then something()
will not be called.
Heres an example:
(function() {
angular.module('MyApp', [])
.controller('MyController', MyController);
MyController.$inject = ["$scope"];
function MyController($scope) {
$scope.disabled = true;
}
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div data-ng-app="MyApp">
<div data-ng-controller="MyController">
<button type="button" ng-disabled="disabled" ng-click="disabled || something()">No Click Please!</button>
<button type="button" data-ng-click="disabled = !disabled">{{disabled ? 'Enable' : 'Disable'}}</button>
</div>
</div>
Notice you can also use the ngDisabled
directive so that if $scope.disabled
is true, something()
will not be called and the button will also be disabled!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With