0

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>

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

Comments

1

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.