Reputation: 227
i have a list of radio buttons,value of those buttons came from ajax request inform of json data.i have binded it to list but i want to get selected value from the list,i tried as below with no luck.
html
<ons-list-item modifier="tappable" ng-repeat="area in AreaList">
<label class="checkbox checkbox--list-item" >
<input type="radio" ng-bind="area.name" ng-model="selectedValue" name="area" value="area.code">
<div class="checkbox__checkmark checkbox--list-item__checkmark"></div>
{{area.name}}
</label>
</ons-list-item>
js
//PARING FOR AREA
if(data.Details[i] === "Area"){
for(var d=0;d<17;d++){
var area =data.Details[i+1][d]['varCityName'];
var code = data.Details[i+1][d]['intGlCode'];
$scope.AreaList.push({name:area, code:code});
area = '';
code = '';
$scope.selectedValue = data.Details[i+1][d]['intGlCode'];
}
console.log("===========AREA obj===========", $scope.AreaList);
}
.
.
.
.
$scope.submitAnswer=function(list,rate,areaobj)
{
gList = list.name;
alert("-----------my selected area is=========="+gArea);
};
area object printed in console.long
[
Object{
name="Camana Bay",
code="32"
},
Object{
name="Breakers",
code="1"
},
Object{
name="Grand Cayman",
code="2"
},
Object{
name="Bodden Town",
code="16"
},
Object{
name="Cayman Brac",
code="15"
},
Object{
name="East End",
code="20"
},
Object{
name="George Town",
code="21"
},
Object{
name="George Town West",
code="22"
},
Object{
name="Little Cayman",
code="23"
}
]
Upvotes: 0
Views: 1492
Reputation: 3774
Try:
<input type="radio" ng-bind="area.name" ng-model="selectedArea" name="area" ng-value="area.code">
ng-model takes the variable on which the selected value will be stored.
ng-value takes the value that will be stored in ng-model if the particular radio button will be selected
Check out this jsbin
Upvotes: 2