Ajinkya Sawant February 2016

Get value of checked radio button in radio button in Angular JS which as ng-repeat

Here is the code on selection of any one of the radio button i need to get the value

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

Answers


RIYAJ KHAN February 2016

Your HTML should be like this.

 <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

}


Mahesh Sapkal February 2016

Don't know from surveyData.SurveyTypeName is coming from.

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

PLUNKER


shaishab roy February 2016

You should assign value from your repeat-loop not from model value and no need to use {{}} for ng-value

so use ng-value="SurveyType.Name" instead of ng-value="{{surveyData.SurveyTypeName}}" so selected radio button value set to surveyData.SurveyTypeName.

If you want to select anyone by default you can assign value to surveyData.SurveyTypeName like $scope.surveyData={SurveyTypeName: 'second'} then that radio button shown as selected that has value second.

HTML:

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

PLUNKER DEMO

Post Status

Asked in February 2016
Viewed 1,178 times
Voted 11
Answered 3 times

Search




Leave an answer