[英]Getting element id from Controller in Angularjs
Is it possible to add the element id in Angular, 是否可以在Angular中添加元素ID,
<div class="col-sm-8">
<select class="form-control input-sm"
id="ruleResetType"
name="ruleResetType"
ng-model="rule.resetType"
ng-options="data as data for data in Type"
ng-required="true"
ng-disabled="isEditable(id)">
</select>
</div>
I wonder if is it possible to add id at isEditable(id)", I mean the id shall be the element.id? 我想知道是否可以在isEditable(id)处添加ID ,我的意思是ID应该是element.id?
This should work, but like Greg says, you probably don't want to use the element id. 这应该可行,但是就像Greg所说的那样,您可能不想使用元素ID。
app.directive("disableIfIn", function(){
return {
restrict: 'A',
transclude: true,
scope: {
disabledElements: '@disableIfIn'
},
template: '<div ng-transclude></div>',
link: function (scope, element, attrs) {
if(scope.disabledElements.indexOf(attrs.id) === -1){
element.prop('disabled', false);
}
}
};
});
Then (assuming the existence of disabledElements on your scope and elements are disabled by default) add this attribute to your HTML elements: 然后(假设您的作用域和元素上默认存在disabledElements被禁用)将此属性添加到HTML元素中:
disable-if-in="{{disabledElements}}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.