0
当给定指令的给定属性具有特定名称时,我想给出诸如“select,input,textarea,button”的某些元素只读。如何动态地使表单元素只读为角度指令?
此问题中的所有代码都被缩小以使其更加清晰。
例如有一项指令“动态输入场”这个元素:
<ui-select ng-model="controllerData.header.subsidiary"
theme="bootstrap"
class="googleSearch"
ng-disabled="quotationData.readOnly || isFieldDisabled('subsidiary')"
on-select="subsidiaryChanged(controllerData.header.subsidiary)"
dynamic-input-field="A">
<ui-select-match allow-clear="true" autofocus="true" placeholder="Subsidiary">{{$select.selected.description}}</ui-select-match>
<ui-select-choices repeat="subsidiary in presetData.subsidiariesChange | filter: {'description': $select.search}">
<div ng-bind-html="subsidiary.description | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
有了这个指令我想禁用此UI选元素时,它具有一定的名字(在这种情况下,它是“A”)
我试过了很多可能性,但我找不到合适的方法来做到这一点。这是我的指令:
'use strict';
/**
* @ngInject
*/
module.exports = function() {
return {
restrict: 'A',
compile: function (element, attrs) {
if (attrs.dynamicInputField === "A") {
// I have tried all these options but it doesn't seem to disable the select element
// element.prop('disabled', 'disabled');
// element.attr("ng-disabled", 'isReadOnly');
// element.attr("ng-disabled", 'true');
// element.attr("ng-disabled", true);
// element.attr("ng-disabled", 'disabled');
// element.prop('readonly', true);
}
}
};
};