简体   繁体   中英

angular.js - ng-disabled not working

I want to only enable my button if the textfield have input but I can't get ng-disabled to work:

<form novalidate>
    <button type="submit" ng-click="add('+')" ng-disabled="bittext.$invalid">Done</button>   
    <textarea type="text" ng-model="bittext"  size="30" placeholder="add bittext here" style="width: 212px; height:100px" required=""></div>
</form>

But when I tried(without the $invalid )

<form novalidate>
        <button type="submit" ng-click="add('+')" ng-disabled="bittext">Done</button><!-- no '.$invalid'-->  
        <textarea type="text" ng-model="bittext"  size="30" placeholder="add bittext here" style="width: 212px; height:100px" required=""></div>
    </form>

it will disable my button when I input something in the text field.

try ng-disabled="!bittext" . Also in your first paste you have bit text (space). That may be why it wasn't working.

  1. your using form so you can try like this also

     <form name="form" novalidate> <button type="submit" ng-click="add('+')" ng-disabled="form.$invalid">Done</button> <textarea type="text" ng-model="bittext" size="30" placeholder="add bittext here" style="width: 212px; height:100px" required=""></textarea> </form> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM