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

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

问题描述

是否可以通过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组件绑定到角度范围
  • ng-click更改为ng-change
  • 如果必须在选中和取消选中复选框时绑定一些值,请使用ng-true-value="someValue"ng-false-value="someValue"
  • Use ng-model if you want to bind a html component to angular scope
  • Change ng-click to ng-change
  • If you have to bind some value upon checking and un-checking the checkbox use ng-true-value="someValue" and 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

工作演示

Working Demo

<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天全站免登陆