javascript - Why is ng-disabled not working on button? -
my plunkr: http://plnkr.co/edit/4mkenjpczfbxy5aoilll?p=preview
<body ng-controller="mainctrl main"> <h1>hello plunker!</h1> <p>button should not disabled:</p> <div ng-init="main.btndisabled = false"> <button ng-model="main.my_button" ng-class="{ 'btn-success' : !tc.switching, 'btn-disabled' : tc.switching }" disabled="main.btndisabled" type="button" class="btn btn-info btn-sm switch-btn">my button</button> </div>
angular
angular.module('app').controller('mainctrl', function($scope) { vm = this; vm.btndisabled = false; });
i found this answer here, didn't work in example.
the button disabled because there disabled
attribute. enough browser know element must inactive. value disabled attribute
doesn't matter, can anything.
this reason why angular provides ngdisabled
directive, adds disabled
attibute when expression evaluates true
, , removes when it's false
.
in case should use
<button ng-model="main.my_button" ng-class="{ 'btn-success' : !tc.switching, 'btn-disabled' : tc.switching }" ng-disabled="main.btndisabled" type="button" class="btn btn-info btn-sm switch-btn">my button</button>
Comments
Post a Comment