How to disable a button in ANGULARJS

i have an angular value of JS 1.5.0-rc.2

I found on the Internet that I can use the directive

data-ng-disabled="Expression"

But he will not turn off the 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 to disable the button? Thanks

+4
source share
3 answers

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>
Run code
+4
source
Try this 
1 This is direct method of implementation
<script>src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
  <button ng-disabled=true>test</button>
</div>

2 another way you can change the value for 



<div ng-app>
  <button ng-disabled=dsblBtn>test</button>
</div>

in controller inside init function 

$scope.dsblBtn = true;
+1
source

. :

<a href="" id="trash" class="cntrbtn remove pull-left disabled" ng-click="disabled||usertaskctrl.removeTasksToArchive()" ng-disabled="disabled">remove</a>

$scope.disabled = true;

if/else disabled $scope.disabled = false;

I give you an example with a tag <a></a>this button operation is simple.

And in the ng-click button ng-click="disabled||usertaskctrl.removeTasksToArchive()", a test is first performed before clicking on any function.

+1
source

Source: https://habr.com/ru/post/1675890/


All Articles