角度复选框和 ng-click [英] Angular checkbox and ng-click

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

问题描述

Angular 1.2:

Angular 1.2:

<input type="checkbox" ng-model="vm.myChkModel" ng-click="vm.myClick(vm.myChkModel)">

我的 myClick 函数没有正确的状态?

I don't have the right state in my myClick function?

我想要点击后的状态.

推荐答案

ng-clickng-model 的执行顺序不明确,因为它们没有定义明确的优先事项.相反,您应该在 $scope 上使用 ng-change$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.

在你的情况下,这应该有效:

In your case, this should work:

<input type="checkbox" ng-model="vm.myChkModel" ng-change="vm.myClick(vm.myChkModel)">

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

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