Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

angularjs - Get all values when button is pressed

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.

Here is the link to plunker:

http://plnkr.co/edit/YKtWm8kaLOIUfc09ZSCA?p=preview

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

  ];
});

Thanx.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is an updated Plunker:

http://plnkr.co/edit/OnHXect37Phij9VAB0ET

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...