javascript 在 Angular 中禁用选择?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29181002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable select in Angular?
提问by Chaps
On page is located HTML select list:
在页面上位于 HTML 选择列表中:
<select ng-model="names" disabled="{{disabled}}" name="names" class="form-control input-medium">
<select ng-model="names" disabled="{{disabled}}" name="names" class="form-control input-medium">
And in controller:
在控制器中:
$scope.disabled = true;
And ng-change
:
并且ng-change
:
$scope.changeSpecialization = function (id){
console.log(id); // Gives value more that 0
if(id > 0){
$scope.disabled = false;
}
}
How you can see in method changeSpecialization
I catch id
and check it to zero. Console returns me value more that zero. So after is changed $scope.disabled
to false. But on page select list is still disabled.
您如何在changeSpecialization
我捕获的方法中看到id
并将其检查为零。控制台返回的值大于零。所以after改为$scope.disabled
false。但是在页面选择列表上仍然被禁用。
回答by Satpal
You should use ngDisableddirective.
您应该使用ngDisabled指令。
This directive sets the disabled attribute on the element if the expression inside ngDisabled evaluates to truthy.
如果 ngDisabled 中的表达式计算结果为真,则该指令在元素上设置 disabled 属性。
Code Example
代码示例
<select ng-disabled="disabled" ng-model="names" name="names">
</select>