我必须在ng repeat中获取radiobox的检查值,其值是动态的

时间:2016-12-17 14:27:50

标签: javascript angularjs

我正在尝试使用foreach获取已检查单选按钮的值,但它显示为undefine。

代码如下所示:

           <form name="exitEmp" ng-submit=submit(exitEmp) novalidate>

                    <table>

                        <tr>
                        <th>S.No</th>
                        <br />

                            <th>Factors</th>
                            <th>Poor</th>
                            <th>Average</th>
                            <th>Above Average</th>
                            <th>Good</th>
                 <th>Excellent</th>                                                         </tr>
                 <div >
               <div>
             <tr ng-if="feedback.qtype=='radio'" ng-repeat="feedback in empratingquestion" >

                                                                    <td>1</td>
                                                                      <td>{{feedback.question}}</td>
                                        <td><input type="radio"  value={{feedback.value}} ng-model="feedback.value.selected"></td>
                                                                    <td><input type="radio" ></td>
                                                                    <td><input type="radio"></td>
                                                                    <td><input type="radio"></td>
                                                                    <td><input type="radio"></td>

                                                                </tr>

                                                        </div>
                                                        </div>
                                                        </div>

                                                    </table>



                                                    <div class="clearfix"></div>

                                                    <div class="center">
                                                        <input type="submit" value="submit">
                                                    </div>
                                                </form>

这里是控制器:

$scope.selectedItems=[];
$scope.submit=function(form) {
    angular.forEach($scope.empratingquestion,function(feedback){
        if(feedback.value.selected){        
            $scope.selectedItems.push(feedback.value);          
        }
    })
    alert($scope.selectedItems)
}

1 个答案:

答案 0 :(得分:0)

显示 empratingquestion 对象..将您的代码放入jsfiddle或其他。 试试这个..

<label class="radio-button" ng-repeat="feedback in empratingquestion">
            <input type="radio" ng-model="feedback.name" name="evaluatorOptions" ng-value="{{feedback.name}}">{{feedback.name}}
        </label>