How to disable a button in ANGULARJS

Vincent Ducroquet picture Vincent Ducroquet · Apr 28, 2017 · Viewed 53.6k times · Source

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

Answer

Pengyy picture Pengyy · Apr 28, 2017

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>