在Angularjs中从Controller获取元素id
Getting element id from Controller in Angularjs
是否可以在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>
我想知道是否可以在isEditable(id)中添加id,我的意思是id应该是元素。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);
}
}
};
});
然后(假设在你的作用域中存在disabledElements并且元素默认是禁用的)将这个属性添加到你的HTML元素中:
disable-if-in="{{disabledElements}}"
相关文章:
- 选择不带选择器的元素,仅使用元素ID
- 从元素id中获取值,而不是从javascript中的名称中获取值
- 如何将第二个元素id注入到网站元素中
- 将 JavaScript 元素 ID 传递给 PHP 或 Form Variable
- 如何在 javascript 中将表单中的元素 id 值作为数组传递
- 用于指定元素 ID 的正确 JavaScript 语法是什么
- 如何从 jQuery 中的 ajax 函数中的类访问元素 ID
- JavaScript获取多个已知元素ID
- 使用ng repeat时元素ID重复
- 在使用onblur进行输入评估时,是否可以获得单击对象的元素id
- JQuery通过变量标识元素id:多个表行
- 当元素ID包含美元符号时,Javascript中的getElementByid.当ID包含美元符号时,
- 我得到未捕获的类型错误:无法读取属性'选项'即使定义了元素id,也为null
- 元素id未被接受为函数参数
- 使用jquery获取类元素id
- 如何在没有任何元素id的情况下检索表中的文本内容
- jquery按类确定元素id
- 获取元素ID并传递到函数中
- 使用jquery获取元素id
- JavaScript文档.getElementById(“id”)和元素id属性