Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了AngularJS – 选择由ng-repeat生成的单选按钮时不会更新的模型大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
使用Ng-repeat生成一堆单选按钮,然后在选择其中@L_874_1@时尝试更新模型。这似乎不工作。

相同的代码标记工作正常,当无线电输入硬编码,而不是由ng-repeat生成

这工作:

<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}}

这不:

<input type="radio" ng-model="lunch" ng-repeat="m in meat" value="m" name="lunch">    
{{lunch}}

看到j​​sfiddle在这里显示http://jsfiddle.net/mark_up/A2qCS/1/

任何帮助将不胜感激。

谢谢

<div ng-controller="DynamicCtrl">
    <input type="radio" ng-model="$parent.lunch" ng-repeat="m in meat"  
    ng-value="m" name="lunch">    
    {{lunch}}
</div>

应该做的伎俩。

根据我的理解,ng-repeat创建自己的$范围。所以你需要引用$ parent $ scope;是的,AngularJS是棘手的。还需要将值更改为ng-value。

大佬总结

以上是大佬教程为你收集整理的AngularJS – 选择由ng-repeat生成的单选按钮时不会更新的模型全部内容,希望文章能够帮你解决AngularJS – 选择由ng-repeat生成的单选按钮时不会更新的模型所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。