[英]Disable AngularJS dropdown multiselect
我有一個指令來禁用angularjs dropdown multiselect,該指令在更改復選框時正常工作,但是在初始化控件時不起作用,我想通過啟動控制器時傳遞給該指令的值來禁用下拉菜單。
那就是指令:
var FormModule = angular.module('FormModule', []);
FormModule.directive('ngDropdownMultiselectDisabled', function () {
return {
restrict: 'A',
controller: function ($scope, $element, $attrs) {
var $btn;
$btn = $element.find('button');
return $scope.$watch($attrs.ngDropdownMultiselectDisabled, function (newVal) {
return $btn.attr('disabled', newVal);
});
}
};
});
這是下拉列表的div:
<div class="col-sm-3">
<input id="chkHasParent" type="checkbox" class="form-control"
ng-model="property.HasParent" ng-checked="property.HasParent==true" />
<label for="chkHasParent" class="lblCheck">Has Parent</label>
</div>
<div class="col-sm-3">
<label>Parent Property</label>
<div id="ddlParentProperty" ng-dropdown-multiselect=""
options="Properties" selected-model="parentPropertyModel"
extra-settings="settingParentProperty"
ng-dropdown-multiselect-disabled="!property.HasParent">
</div>
</div>
如果沒有人知道,那就是Angular js下拉菜單multiselect的文檔 。
$scope.hasParentChange = function hasParentChange(hasParent) {
if (hasParent != null) {
if (hasParent == false) {
document.getElementById("ddlParentProperty").getElementsByTagName('button')[0].setAttribute("disabled", "disabled");
}
else {
document.getElementById("ddlParentProperty").getElementsByTagName('button')[0].removeAttribute("disabled");
}
}
else {
document.getElementById("ddlParentProperty").getElementsByTagName('button')[0].setAttribute("disabled", "disabled");
}
}
angular.element(document).ready(function () {
$scope.hasParentChange($scope.property.HasParent)
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.