我有一个HTML按钮选项,如下所示,
{(0,2), (2,0,1)}
上面的按钮选项中没有<button ng-class="{'primaryButton':true}" type="button" id="modalCreateBtn" "ng-hide="false" class="btn btn-group mm-btn-save primaryButton" ng-click="addSegments()">CREATE</button>
选项。这可以通过控制器上的buttonId启用/禁用按钮吗?另外,我不想在HTML视图上添加禁用选项。相反,我想通过脚本来控制它。这可能吗?
答案 0 :(得分:14)
你有没有看过ngDisable? 您可以拥有ngModel并从控制器更改它。就像文档示例所说:
<span ng-controller="MyController as myController">
<label>Click me to toggle: <input type="checkbox" ng-model="myController.checked"></label><br/>
<button ng-model="button" ng-disabled="myController.checked">Button</button>
</span>
和JS:
angular.module('controllerAsExample', [])
.controller('MyController ', function(){
this.checked = false;
// this.checked = true;
});
答案 1 :(得分:11)
使用ng-disabled
是启用/禁用按钮的最佳做法,但您也可以在控制器中实现它,而无需使用此脚本将disabled
属性添加到HTML视图中,
angular.element(document.getElementById('yourButtonId'))[0].disabled = true;
在你的情况下,
angular.element(document.getElementById('modalCreateBtn'))[0].disabled = true;
希望这有帮助!
答案 2 :(得分:0)
您是否尝试过使用ng-if?
控制器:
$scope.setUploadMode = function (stats) {
if (stats == 4) {
$scope.selectMe = false;
} else { alert("No"); $scope.selectMe = true; }
};
$scope.hello = function () {
alert("YEY");
};
HTML:
div class="radio">
<label>
<input type="radio" name="appendCreateMode" ng-disabled="uploadMode != 2" ng-click="setUploadMode(4)" />Append Folder
</label>
</div>
<button ng-model="button" ng-disabled="selectMe" ng-click="hello()">Button</button