I'm trying to disable enable a button based on an input type value. Here is the Angular JS html code
<div ng-app>
<form name="myForm" ng-controller="ctrl">
<input type="text" ng-model="name" ng-required="true" />
<span>{{name}}</span>
<input type="submit" value="Submit" ng-disabled="myForm.name.$pristine" />
</form>
</div>
And the controller code:
function ctrl($scope){
$scope.name = "hello";
}
But the button is not getting disabled no matter what.
Here is the DEMO
NOTE: I want the button to be disabled only when text box doesn't have any value and vice versa
Try this
<input type="submit" value="Submit" ng-disabled="name==undefined || name==''" />
Hope it helps.....................
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With