NG-检查= QUOT;真"在复选框被忽略 [英] ng-checked="true" being ignored on checkbox
问题描述
我有一个复选框的选中状态( NG-检查
)是基于计算的特性( NG-检查=someFunction()
)。
I have a checkbox whose checked state (ng-checked
) is based on a computed property (ng-checked="someFunction()"
).
例如起见,我们假设其检查的状态应始终检查,即: NG-检查=真
For the sake of example, let's assume its check state should always be checked, ie: ng-checked="true"
.
但是,单击该复选框会取消它,这意味着还有的 NG-检查
申报和复选框的实际状态之间的脱节:
However, clicking on the checkbox will uncheck it, meaning there's a disconnect between the ng-checked
declaration and the actual state of the checkbox:
<input type="checkbox" ng-checked="true">
那么,为什么点击复选框使其选中,如果 NG-检查
始终是真的吗?
So why does clicking the checkbox make it unchecked if ng-checked
is always true?
推荐答案
NG-检查不打算锁定复选框的值,它是一个单向绑定,更新的复选框,只有当财产与其绑定更新。你也不能绑定到原语(在这种情况下,一个布尔值),则必须绑定到一个对象的属性。
ng-checked is not intended to lock the value of a checkbox, it is a one way binding which updates the checkbox only when the property its bound to is updated. Also you can not bind to primitives (in this case a boolean value), you must bind to a property of an object.
如果要禁用此复选框,使用禁用=true属性。
If you want to disable this checkbox, use the disabled="true" attribute.
这篇关于NG-检查= QUOT;真&QUOT;在复选框被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!