Reputation: 500
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
Upvotes: 0
Views: 2786
Reputation: 28750
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">
Upvotes: 1