angularjsbuttoninputauthenticationangularjs-ng-disabled

Login page not working angular js


I am trying to disable my Login button, when nothing is present in the form fields. I am already using ng-disabled, could any body help why it is not getting disabled. Find the sample code below: I have checked in previous posts but the code written there is almost the same as that to the format. I am still not able to disable it

<b>
        <form role="form" name="form" id="form" ng-submit="loginValidate()">
<div class="jumbotron">
<div class="form-group">        
<label>Username &nbsp;</label> <input class="form-text" type="text" ng-model="username" name="username" />                  
</div>                      
<div class="form-group">                        
<label>Password &nbsp;</label> <input class="form-text" type="text" ng-model="password" name="password" />       
</div>                  
<div>
<p>                     
<button type="submit" class="btn btn-primary"                           
ng-click="submitted=true" ng-disabled="form.$invalid">Login</button>        
</p>                    
</div>                  
</form>
<b>

The form defined here is a simple form, yet i am not able to disable the Login button


Solution

  • Probably you missed to use "required" tag in input fields!

    try like below once

    <b>
    <form role="form" name="form" id="form" ng-submit="loginValidate()">
    <div class="jumbotron">
    <div class="form-group">        
    <label>Username &nbsp;</label> <input class="form-text" type="text" ng-model="username" name="username" required />                  
    </div>                      
    <div class="form-group">                        
    <label>Password &nbsp;</label> <input class="form-text" type="text" ng-model="password" name="password" required />       
    </div>                  
    <div>
    <p>                     
    <button type="submit" class="btn btn-primary"                           
    ng-click="submitted=true" ng-disabled="form.$invalid">Login</button>        
    </p>                    
    </div>                  
    </form>
    <b>