我想为复选框使用两种方式的绑定,但是如果使用[(ngModel)]
它,它会显示true或false而不是选中项的值。有人知道这是怎么做的吗?
如果我想使用双向绑定并将其设置为“ expression.value”,我该怎么做:
<input type="checkbox" type="checkbox"/> Option 1</a></li>
在这种情况下,我想将复选框的值绑定:选项1到表达式类中。
这是一个已知的问题
有不同的解决方法,例如使用event.target.checked
代替模型中的值。
您可以使用
<input type="checkbox"
(change)="expression && expression.Option1=$event.target.checked ? true : undefiend"
[ngModel]="expression?.Option1">
<input type="checkbox"
(change)="expression && expression.Option2=$event.target.checked ? true : undefiend"
[ngModel]="expression?.Option2">
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句