Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS : ng-disable not working

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

like image 214
iJade Avatar asked Nov 29 '22 11:11

iJade


1 Answers

Try this

<input type="submit" value="Submit" ng-disabled="name==undefined || name==''" />

Hope it helps.....................

like image 151
Alagarasan M Avatar answered Dec 11 '22 09:12

Alagarasan M