AngularJS - 不更新对NG-重复产生单选按钮的选择模型 [英] AngularJS - Model not updating on selection of radio button generated by ng-repeat
问题描述
我使用的NG-重复生成大量单选按钮,然后尝试当选择其中一个更新的模式。这似乎并不奏效。
当无线电输入是相对于吴重复生成硬codeD相同的code标记的作品就好。
本作品:
<输入类型=电台NG-模式=午餐值=鸡NAME =午餐>
<输入类型=电台NG-模式=午餐值=牛肉NAME =午餐>
<输入类型=电台NG-模式=午餐值=鱼NAME =午餐>
{{午餐}}
这不:
<输入类型=电台NG-模式=午餐NG-重复=米肉值=MNAME =午餐>
{{午餐}}
请参阅的jsfiddle显示都在这里: http://jsfiddle.net/mark_up/A2qCS/1/
任何帮助将是AP preciated。
感谢
< DIV NG控制器=DynamicCtrl>
<输入类型=电台NG-模式=$ parent.lunchNG重复=米肉
NG-值=MNAME =午餐>
{{午餐}}
< / DIV>
应该做的伎俩。
据我了解,NG-重复创建自己的$范围。所以你需要参考$父$范围;是的,AngularJS是棘手的。和值
更改为 NG-值
了。
I am generating a bunch of radio buttons using ng-repeat, and then trying to update a model when one of them is selected. This doesn't appear to be working.
The same code markup works just fine when the radio inputs are hardcoded as opposed to being generated by ng-repeat.
This works:
<input type="radio" ng-model="lunch" value="chicken" name="lunch">
<input type="radio" ng-model="lunch" value="beef" name="lunch">
<input type="radio" ng-model="lunch" value="fish" name="lunch">
{{lunch}}
This doesn't:
<input type="radio" ng-model="lunch" ng-repeat="m in meat" value="m" name="lunch">
{{lunch}}
See jsfiddle showing both here: http://jsfiddle.net/mark_up/A2qCS/1/
Any help would be appreciated.
Thanks
<div ng-controller="DynamicCtrl">
<input type="radio" ng-model="$parent.lunch" ng-repeat="m in meat"
ng-value="m" name="lunch">
{{lunch}}
</div>
Should do the trick.
as i understand it , ng-repeat creates its own $scope. so you need to refer to the $parent $scope; Yes , AngularJS is tricky. and change value
to ng-value
too.
这篇关于AngularJS - 不更新对NG-重复产生单选按钮的选择模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!