【问题标题】:AngularJS : ng-repeat on radio buttonAngularJS:单选按钮上的 ng-repeat
【发布时间】:2015-09-29 21:20:39
【问题描述】:

您好,我正在尝试实现一个 html,当您单击单选按钮时,我想更新我的 Obj。

所以当我点击保存按钮时,我会将我的 Obj 发送到 api 以保存数据。

我的问题是我不知道如何制作一个可以更新我的 obj 的单选按钮?

这可能吗?

 scope.Obj =   [
      {
        "condition": "Question1",
        "status": ""
      },
      {
        "condition": "Question2",
        "status": ""
      },
      {
        "condition": "Question3",
        "status": ""
      }
     ]

HTML 输出

Question                                    Status (Radio Button)

Question1                                      yes[]    no[]
Question2                                      yes[]    no[]
Question3                                      yes[]    no[]

                                                 [ Save ]

【问题讨论】:

标签: angularjs angularjs-directive angularjs-scope angularjs-ng-repeat


【解决方案1】:

如果您只是显示您的对象,您会看到它已绑定到值。

<div ng-repeat="o in obj">
      Yes <input type="radio" ng-model="o.status" value="yes" />
      No <input type="radio" ng-model="o.status" value="no"  /> 
...

{{obj}}

这是fiddle

【讨论】:

    猜你喜欢
    • 2022-11-11
    • 2015-06-27
    • 2015-05-07
    • 2016-04-22
    • 2016-02-10
    • 1970-01-01
    • 2015-09-22
    • 2014-06-14
    • 2016-05-24
    相关资源
    最近更新 更多