AngularJS 条件 ng-disabled 不重新启用 [英] AngularJS conditional ng-disabled does not re-enable

查看:28
本文介绍了AngularJS 条件 ng-disabled 不重新启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个使用 ng-disabled="truthy_scope_variable" 条件禁用的文本输入字段,AngularJS 会在 第一次范围变量被伪造时禁用该字段,但不会启用它在随后的变化.因此,该字段保持禁用状态.我只能假设出了点问题,但控制台日志是空的.

Given a conditionally disabled text input field using ng-disabled="truthy_scope_variable", AngularJS disables the field the first time the scope variable is falsified, but does not enable it on subsequent changes. As a result, the field remains disabled. I can only assume something went wrong, but the Console log is empty.

truthy 范围变量与单选按钮模型相关联,我什至可以$watch 更改它,但是输入字段的 ng-disabled 没有按预期工作.我已经手动尝试调用 $apply,但看起来 Angular 正在触发 DOM 更改.

The truthy scope variable is tied to a radio button model and I can even $watch it change, but the input field's ng-disabled is not working as expected. I have manually tried calling $apply, but it looks like Angular is triggering DOM changes.

$scope.new_account = true

单选按钮:

<input type="radio" ng-model="new_account" name="register"
 id="radio_new_account" value="true" />

<input type="radio" ng-model="new_account" name="register"
 id="radio_existing_account" value="false" />

有条件地禁用输入字段:

<input type="password" ng-disabled="new_account" id="login-password"
 name="password" ng-model="password" />

如果我最初设置 $scope.new_account = false,该字段将被禁用,但永远不会重新启用.为什么会发生这种情况?

If I initially set $scope.new_account = false, the field is rendered disabled, but never re-enabled. Why is this happening?

推荐答案

有一个替代解决方案可用,只需使用

There is an alternative solution available just use

ng 值

 <input type="radio" ng-model="new_account" name="register"
 id="radio_new_account" ng-value="true" />

<input type="radio" ng-model="new_account" name="register"
 id="radio_existing_account" ng-value="false" />
      <input type="password" ng-disabled="new_account" id="login-password"
 name="password" ng-model="password" />

这篇关于AngularJS 条件 ng-disabled 不重新启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆