Below is my code where I do not get the selected radio option for each of the corresponding lines, let me know what I'm doing wrong here.
My Plnkr Code - http://plnkr.co/edit/MNLOxKqrlN5ccaUs5gpT?p=preview
Although I get the names for the classes object, I don't get the selection.
HTML code -
<body ng-controller="myCtrl"> <div class="container-fluid"> <form name="formValidate" ng-submit="submitForm()" novalidate="" class="form-validate form-horizontal"> <div class="form-group"> <label class="col-sm-2 control-label">Name</label> <div class="col-sm-6"> <input type="text" name="name" required="" ng-model="classes.name" class="form-control" /> </div> </div> <div class="form-group"> <table id="datatable1" class="table table-striped table-hover"> <tr class="gradeA" ng-repeat="cls in reqgrps"> <td ng-bind="cls.name"></td> <td><input type="radio" name="groupName[{{$index}}]" ng-model="classes.satisfies"> Choice 1</td> <td><input type="radio" name="groupName[{{$index}}]" ng-model="classes.satisfies"> Choice 2</td> <td><input type="radio" name="groupName[{{$index}}]" ng-model="classes.satisfies"> Choice 3</td> </tr> </table> </div> <div class="panel-footer text-center"> <button type="submit" class="btn btn-info">Submit</button> </div> </form> </div> <div class="result">{{classes}}</div> </body>
Script File -
var myApp = angular.module('myApp', []); myApp.controller('myCtrl', function($scope){ $scope.reqgrps = [{name: 'Sub1', roll: 121},{name: 'Sub2', roll: 122}, {name: 'Sub3', roll: 123}]; $scope.classes = {}; $scope.result = {}; $scope.submitForm = function() { $scope.result = $scope.classes; }; });
------------- EDIT -------------
Expected Result -
obj classes -
{ name: "Test Class", satisfies: [ "Sub1": "Choice 1", "Sub2": "Choice 3", "Sub3": "Choice 2", ................. .................. .................. .................. "Subn": "Choice 2", ] }
source share