gpt4 book ai didi

javascript - 更改 AngularJS 中选中和未选中的复选框值

转载 作者:太空宇宙 更新时间:2023-11-04 15:38:58 24 4
gpt4 key购买 nike

我有一个复选框,如果选中或未选中该复选框,我想更改该值。

目前,如果选中,我的复选框模型值等于“true”,如果未选中,则等于“false”。

我的复选框

<input type="checkbox" ng-model="toStringObj" />

我尝试了什么

<input type="checkbox" ng-true-value="anyModel" ng-false-value="''" ng-model="toStringObj" />

如果我在 ng-true-value 指令中放置一个字符串,但不使用模型,我就可以工作,我需要从我的范围传递一个模型

最佳答案

不幸的是,ngTrueValuengFalseValue 仅接受常量表达式,因此不可能从 Controller 作用域上的值动态设置它们。

Some attributes used in conjunction with ngModel (such as ngTrueValue or ngFalseValue) will only accept constant expressions.

https://docs.angularjs.org/error/ngModel/constexpr

关于javascript - 更改 AngularJS 中选中和未选中的复选框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44049382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com