获取Angular JS中单选按钮中选中的单选按钮的值,作为ng-repeat

时间:2016-02-08 11:03:46

标签: javascript jquery angularjs

以下是选择我需要获取值

的任何一个单选按钮的代码
<label ng-repeat="SurveyType in SurveyTypes">
    <input type="radio" name="SurveyTypeName" ng-model="surveyData.SurveyTypeName" ng-value="{{surveyData.SurveyTypeName}}" />
    {{SurveyType.Name}} &nbsp; &nbsp; &nbsp;
</label>

3 个答案:

答案 0 :(得分:1)

您应该从value分配repeat-loop而不是model分配{{}}而不需要ng-value ng-value="SurveyType.Name"

因此请使用ng-value="{{surveyData.SurveyTypeName}}"代替surveyData.SurveyTypeName,以便将所选的单选按钮值设置为surveyData.SurveyTypeName

如果您希望默认选择任何人,则可以将值$scope.surveyData={SurveyTypeName: 'second'}分配给second,然后选择显示为选中且值为<label ng-repeat="SurveyType in SurveyTypes"> <input type="radio" name="SurveyTypeName" ng-model="surveyData.SurveyTypeName" ng-value="SurveyType.Name" /> {{SurveyType.Name}} &nbsp; &nbsp; &nbsp; </label> 的单选按钮。

<强> HTML:

category

PLUNKER DEMO

答案 1 :(得分:0)

您的HTML应该是这样的。

 <input type="radio" name="SurveyTypeName" ng-model="surveyData.SurveyTypeName" ng-value="{{surveyData.SurveyTypeName}}"  ng-change="getval($index)"/> 

的js

$scope.getval = function (index){


 var servetypename =SurveyTypes[index];

var data =servetypename.SurveyTypeName

}

答案 2 :(得分:0)

来自surveyData.SurveyTypeName的不知道来自。

<li ng-repeat="SurveyType in SurveyTypes">
        <input type="radio" name="SurveyTypeName" ng-model="$parent.rdoSelected" ng-value="SurveyType.SurveyTypeName" />
        {{SurveyType.Name}}
</li>

PLUNKER