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);
}
}
};
};