获取所有值时,按钮为pressed [英] Get all values when button is pressed

查看:170
本文介绍了获取所有值时,按钮为pressed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是该方案,我这是通过NG-重复再重复几个列表项。当我们点击提交按钮,我需要选择的单选按钮(ID,名称和说明)的所有信息。我知道我们可以做到在单选按钮上使用这个NG-的变化,但它不符合我的要求。我需要得到它被点击提交按钮时。

Here is the scenario, I have few list items which are repeat via ng-repeat. When we click on the submit button, I need to get all the information of the selected radio button (id, name and description). I know we can achieve this using ng-change on radio buttons, but it does not fulfill my requirement. I need to get it when the submit button is clicked.

下面是链接到plunker:

Here is the link to plunker:

http://plnkr.co/edit/YKtWm8kaLOIUfc09ZSCA?p=$p$ PVIEW

 <form ng-submit="showData()">
      <ul>
        <li ng-repeat="list in lists">
          <input type="radio" name="radiogroup" ng-model="radioMod.value" value="{{list.id}}">
              {{list.name}}
              <br />
          <p>{{list.description}}</p>
        </li>
      </ul>
      <button type="submit">submit</button>
    </form>

我什么也没有添加到控制器...

I have added nothing to the controller...

var myApp = angular.module('myApp', []);

myApp.controller('MainCtrl', function($scope) {

  $scope.lists = [
    {"id": 1, 'name' : 'radio1', 'description' : 'some text for radio1'},
    {"id": 2, 'name' : 'radio2', 'description' : 'some text for radio2'},
    {"id": 3, 'name' : 'radio3', 'description' : 'some text for radio3'}

  ];
});

感谢名单。

推荐答案

下面是一个更新的Plunker:

Here is an updated Plunker:

http://plnkr.co/edit/OnHXect37Phij9VAB0ET

您需要将值设置为整个表对象的 NG-值,无需额外的标志。

You need to set the value to the whole "list" object with ng-value, no need for an additional flag.

这篇关于获取所有值时,按钮为pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆