Reputation: 2262
I am working on Ionic framework on frontend. Basically it is a Cordova app. I want to capture the radio button value in controller but as I'm new in it I don't know how exactly I'll get back my value and what I need to pass in NextQuestion() method in ionic. code is as below.
<div class="list list-inset padding">
<ion-list radio-group>
<ion-item class="item-remove-animate item-icon-right" ng-repeat="answer in CurrentQuestion.answersList" type="item-text-wrap">
<ion-radio ng-value="'{{answer.AnswerID}}'">{{answer.Answer_en}}</ion-radio>
</ion-item>
</ion-list>
</div>
<ion-buttons side="primary">
<button class="button button-block button-calm" ng-click="NextQuestion()">
Next
</button>
</ion-buttons>
Upvotes: 0
Views: 98
Reputation: 409
Ion-radio behavior like input radio of AngularJS.
Basically you need to do it like this ($parent
is because of ng-repeat create a child scope for each item)
<ion-list radio-group>
<ion-item class="item-remove-animate item-icon-right" ng-repeat="answer in CurrentQuestion.answersList" type="item-text-wrap">
<ion-radio ng-model="$parent.selectedAnswer" ng-value="'{{answer.AnswerID}}'">{{answer.Answer_en}}</ion-radio>
</ion-item>
</ion-list>
Upvotes: 1
Reputation: 473
Use ng-model
for two-way binding, in your example, I will do this:
...
<ion-radio ng-model="userSelectedAnswer" ng-value="{{answer.AnswserID}}">
{{answer.Answer_en}}
</ion-radio>
...
Then you can use the selected value in your NextQuestion
function like this:
console.log($scope.userSelectedAnswer);
Upvotes: 2