angularjsbuttonangularjs-ng-disabled

How to disable a button in ANGULARJS


i have angularJS 1.5.0-rc.2

I found on the internet that i can use the directive

data-ng-disabled="Expression"

But it won't disable a button.

What i tried :

<button data-ng-disabled="false">Select</button> // don't work
<button data-ng-disabled="loaded">Select</button> // don't work
<button data-ng-disabled="loaded != false">Select</button> // don't work

Loaded is defined in my controller as $scope.loaded = false.

How can i disable a button ? Thanks


Solution

  • The button will be disabled only if the expression is true.

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app ng-init="disableBtn=true">
      <button ng-disabled="disableBtn">test</button>
    </div>