Search code examples
angularjsangularjs-scope

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 ?


Solution

  • 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>