为ng-repeat单选按钮选择了错误的单选按钮 [英] Incorrect radio button getting selected for ng-repeat radio buttons

查看:81
本文介绍了为ng-repeat单选按钮选择了错误的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ng-repeat的单选按钮列表. 当我最初加载页面并在最后一个单选按钮上进行选择时,其侧面的按钮将被选中. 这仅是第一次发生,也就是说,如果我第二次单击最后一个按钮,则选择正确.

I have a list of radio buttons using ng-repeat. When I initially load the page and select on the last radio button, the button on it's side gets selected. This only happens for the first time, i.e. if I click on the last button a second time, it is selected correctly.

<input type="radio" name="rb" value="{{rbCollection.name}}" data-ng-click="open(name)" data-ng-model="Ctrl.selection">

推荐答案

选中此

问题是ng-click在更新作用域的ng-model代码之前触发.如果您将其更改为使用ng-change,则将对其进行修复.您还需要在文本框中添加ng-change,以根据用户类型更新范围.

The problem is that ng-click fires before the ng-model code that updates the scope. If you change it to use ng-change, that will fix it. You also need to add ng-change to your text box to update the scope as the user types.

这篇关于为ng-repeat单选按钮选择了错误的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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