将复选框值传递给 angular 的 ng-click [英] Pass checkbox value to angular's ng-click

查看:37
本文介绍了将复选框值传递给 angular 的 ng-click的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way to pass to angular directive ng-click the value of the associated input?

换句话说,下面的 this.value 应该用什么代替:

In other words, what should replace this.value in the following:

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

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

PS. I don't want a workaround to alternate values, I just wonder if is possible to pass a value of an input as argument to an angular function.

推荐答案

您可以执行以下操作:

  • 如果需要,请使用 ng-model将 html 组件绑定到 angular 作用域
  • ng-click改为ng-change
  • 如果您必须在选中和取消选中复选框时绑定一些值,请使用 ng-true-value="someValue"ng-false-value="someValue"

ng-clickng-model 的执行顺序不明确,因为它们没有界定明确的优先事项.相反,您应该使用 ng-change或 $scope 上的 $watch 以确保您获得正确的值模型变量.

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 提供

工作演示

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

这篇关于将复选框值传递给 angular 的 ng-click的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆