加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS – 选择由ng-repeat生成的单选按钮时不会更新的模型

发布时间:2020-12-17 08:55:12 所属栏目:安全 来源:网络整理
导读:我使用ng-repeat生成一堆单选按钮,然后在选择其中一个时尝试更新模型。这似乎不工作。 相同的代码标记工作正常,当无线电输入硬编码,而不是由ng-repeat生成。 这工作: input type="radio" ng-model="lunch" value="chicken" name="lunch"input type="radi
我使用ng-repeat生成一堆单选按钮,然后在选择其中一个时尝试更新模型。这似乎不工作。

相同的代码标记工作正常,当无线电输入硬编码,而不是由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。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读