Angular : disable a text input

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

I have an input text which is disabled by default :

 <input type="text" ng-model="city.name" class="form-control"                                    disabled                                    name="name"> 

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

Thanks

回答1:

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"> 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!