AngularJS conditional ng-disabled does not re-enable

前端 未结 3 2052
死守一世寂寞
死守一世寂寞 2021-02-06 21:47

Given a conditionally disabled text input field using ng-disabled=\"truthy_scope_variable\", AngularJS disables the field the first time the scope variable

3条回答
  •  终归单人心
    2021-02-06 22:38

    That's because HTML attributes are always strings, so in your example ngDisabled is evaluating a string in both cases ("true" or "false").

    To remedy, you should compare the model against the string value in ngDisabled:

    ng-disabled="new_account == 'false'"
    

    ... or use a checkbox, to get the actual boolean value:

    
    
    
    Password:
    
    

    Here's a PLNKR with both solutions.

提交回复
热议问题