AngularJS 需要的单选按钮需要两个点击事件才有效 [英] AngularJS required radio buttons needs two click events to be valid

查看:28
本文介绍了AngularJS 需要的单选按钮需要两个点击事件才有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的表单,需要选择一个单选按钮才能使表单有效.单选按钮由 ngRepeat 生成.

I have a very simple form where a radio button is required to be selected in order for a form to be valid. The radio buttons are generated by ngRepeat.

正如你从这个小提琴中看到的,虽然期望的行为是当第一次单击单选按钮时,这应该验证表单(作为唯一的元素),但是请注意它需要额外的点击(在相同的单选按钮或任何其他)来验证表单:

As you can see from this fiddle, while the desired behavior is that when the radio button is clicked for the first time, that should validate the form (being the only element), however notice that it takes an additional click (on the same radio button or any other) to validate the form:

http://jsfiddle.net/Xsk5X/3/

我错过了什么?

推荐答案

尝试将 ng-click 属性添加到您的单选按钮输入中.

Try adding the ng-click attribute to your radio button input.

感谢 Manny D 首先注意到这一点.是的,这有点hackish,但它有效.例如,

Credit to Manny D for noting this first. Yes, this is a little hackish, but it works. E.g.,

<input type="radio" 
       name="groupName"  
       ng-model="editObject.Property"                             
       ng-value="someValue"
       ng-click />

这篇关于AngularJS 需要的单选按钮需要两个点击事件才有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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