AngularJS条件ng-disabled不会重新启用 [英] AngularJS conditional ng-disabled does not re-enable
问题描述
如果使用 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.
真实的范围变量与单选按钮模型相关联,我甚至可以 $ 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
单选按钮:
Radio buttons:
<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" />
有条件禁用的输入栏位:
Conditionally disabled input field:
<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-value
ng-value
<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屋!