gpt4 book ai didi

javascript - 将复选框值传递给 Angular 的 ng-click

转载 作者:行者123 更新时间:2023-12-03 03:45:17 24 4
gpt4 key购买 nike

有没有办法将相关输入的值传递给 Angular Directive(指令) ng-click?

换句话说,应该用什么替换以下内容中的this.value:

<input type="checkbox" id="cb1" ng-click="checkAll(this.value)" />

PS。我不需要替代值的解决方法,我只是想知道是否可以将输入值作为参数传递给 Angular 函数

最佳答案

您可以执行以下操作:

  • 使用ng-model如果你想将 html 组件绑定(bind)到 Angular 范围
  • ng-click 更改为 ng-change
  • 如果您必须在选中和取消选中复选框时绑定(bind)某些值,请使用 ng-true-value="someValue"ng-false-value="someValue"

The order of execution of ng-click and ng-model is ambiguous since they do not define clear priorities. Instead you should use ng-change or a $watch on the $scope to ensure that you obtain the correct values of the model variable.

musically_ut 提供

<强> Working Demo

<input type="checkbox" id="cb1" ng-model="check" ng-change="checkAll(check)" ng-true-value="YES" ng-false-value="NO"/> Citizen

关于javascript - 将复选框值传递给 Angular 的 ng-click,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33431591/

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