Reputation: 13298
In an AngularJS controller, how do I check if a particular field is enabled or disabled? I have looked to the documentation of AngularJS but I didn't found any form field property to indicate the enabled/disabled state of a field.
Upvotes: 2
Views: 5792
Reputation: 31
Angular's jqLite supports prop(). So if you check the .prop('disabled') it should return a boolean with your answer.
Upvotes: 3
Reputation: 13997
Create a variable on your controller and use it on your form:
controller:
$scope.fieldDisabled = true;
$scope.submitForm = function(){
alert("Disabled: " + $scope.fieldDisabled);
}
view:
<form ng-submit="submitForm()">
<input type="text" ng-model="myModel" ng-disabled="fieldDisabled" />
<input type="submit" value="Submit" />
</form>
<button ng-click="fieldDisabled = !fieldDisabled">Toggle disable</button>
Upvotes: 2