Sam Sam -4 years ago 189
AngularJS Question

how to disable or enable button on angularjs?

I have used 2 button in the form. I want to disable button1 on initialisation though I have given

ng-disabled="true"
but whenever user clicks on button2, button1 get enabled. Can anyone tell me how to do this in angularjs ?

Answer Source

You don't need to do anything in the controller if you are not working with the scope variable inside the controller.

So just do something like:

angular.module("app",[]).controller("ctrl",function($scope){})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
        <div ng-app="app" ng-controller="ctrl">
          <button ng-disabled="first !== true"> one</button>
          <button ng-click="first = true"> two</button>
        </div>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download