我在 AngularJS 中有一个简短的表格。
我用 ng-repeat
显示性别并验证其单选按钮
问题是我想获取选中的单选按钮的值并使用 ng-model
打印出来。 .
怎样才能做到这一点?
Here Plunker
最佳答案
Mike Robinson 的解决方案是最优雅的。但是,一个快速的解决方法是添加 $parent:
<input type="radio" ng-model="$parent.selectedGender" name="radiob" id="{{g.id}}" value="{{g.id}}" required />{{g.name}}
这将更改 ng-repeat 的父范围中的 selectGender。
http://plnkr.co/edit/M5cos7xFBA9a0eRWhHi9?p=info
关于来自单选按钮的 AngularJS ng-model 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21460239/