角度:禁用文本输入 [英] Angular : disable a text input
本文介绍了角度:禁用文本输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个默认为禁用的输入文本:
I have an input text which is disabled by default :
<input type="text" ng-model="city.name" class="form-control"
disabled
name="name">
但是我想在输入国家/地区不为null时启用它:
But i want to enable it when the input country is not null :
<input type="text" ng-model="country.name" class="form-control"
>
我该如何在角度控制器中执行此操作?我从这样的事情开始在我的控制器中,但是一旦国家/地区值不为空,我就不知道如何启用它
How can i do this in the angular controller ? i start with something like this in my controller but i dont know how to enable it once the country value is not null
// Watch if the country value is not null
$scope.$watch("country.name", function (value) {
if (value !=null) {
// enable the city field
}
},true);
谢谢
推荐答案
您可以在不进入控制器的情况下使用ng-disabled:
You can use ng-disabled without going into the controller:
<input type="text" ng-model="city.name" class="form-control" ng-disabled="!country.name" name="name">
<input type="text" ng-model="country.name" class="form-control">
这篇关于角度:禁用文本输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文