Ajinkya Sawant
Ajinkya Sawant

Reputation: 100

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>

Upvotes: 0

Views: 1280

Answers (3)

Shaishab Roy
Shaishab Roy

Reputation: 16805

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

Upvotes: 1

msapkal
msapkal

Reputation: 8346

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

Upvotes: 0

RIYAJ KHAN
RIYAJ KHAN

Reputation: 15292

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

}

Upvotes: 0

Related Questions