How to display the checked radio button value in angularJs

anitha

I need to display selected radio button in the response div,if no option is selected that div will disappear.

View Code:

<body ng-app="QuestionDisplayModule">
    <form>
        <div ng-controller="QuestionDisplayController">
            <div ng-repeat="q in questionsData" style="border:groove 1px green">
                <h4 style="color: darkmagenta">{{q.QText}}</h4>
                <p ng-repeat="a in q.answer1" style="color: cadetblue"><input type="radio"  name="answers" ng-model="options" value="{{a.option1}}" ng-checked="optionselected(options)" />{{a.option1}}</p>
                <div>your answer is :{{selectedoption}}</div>
            </div>
        </div>
    </form>
</body>

Script Code:

<script src="~/Scripts/angular.min.js"></script>
    <script>
        var myApp = angular.module("QuestionDisplayModule", [])
        .controller("QuestionDisplayController", function ($scope, $http, $log) {

            $scope.optionselected = function (options)
            {
                $scope.selectedoption = options;
            }
            $http.get("displayQuestion").then(function(response)
            {
                $log.info(response);
                $scope.questionsData = response.data;
            })
        })
    </script>
Shaishab Roy

You should use different name for each question otherwise you will can select only one option for all question and and should use different model for each question and no need to use ng-checked="optionselected(options)" to set selected option value because of you used ng-model.

you can try like this

<div ng-controller="QuestionDisplayController">
      <div ng-repeat="q in questionsData" style="border:groove 1px green">
        <h4 style="color: darkmagenta">{{q.QText}}</h4>
        <p ng-repeat="a in q.answer1" style="color: cadetblue">
          <input type="radio" name="answers+{{$parent.$index}}" ng-model="q.selectedAns" value="{{a.option1}}" />{{a.option1}}</p>
        <div ng-show="q.selectedAns">your answer is :{{q.selectedAns}}</div>
      </div>
    </div>

PLUNKER DEMO

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to display checked value for radio button collection

From Dev

How to display checked radio button based on previous value?

From Dev

How to add checked class to a radio button in AngularJS

From Dev

How to set radio button checked initially in AngularJs?

From Dev

How to add checked class to a radio button in AngularJS

From Dev

How to get radio button checked in AngularJS?

From Dev

how to get checked radio button value in javascript

From Dev

Display radio button checked if json value is match to condition

From Dev

if radio button checked display div

From Dev

AngularJS Change Checked Value of Radio Button Using $scope variable

From Dev

How to get the value of the checked radio button and the remaining td's but not include the radio button that has not been checked (in tr)

From Dev

If radio button checked submit value?

From Dev

How to get value of selected radio button in angularjs

From Dev

How to get radio button value in SweetAlert with AngularJS

From Dev

How to reset Spinner value to "Select by something" based on Radio Button checked

From Dev

How to retrieve radio button value from database in checked state in jsp

From Dev

How to send the checked radio button value to Server in angular js

From Dev

How can i keep the radio button checked and get the value

From Dev

How to set checked="checked" in first radio button?

From Dev

Image Radio Button Checked Display Issues

From Dev

if radio button is checked, display divs and textbox

From Dev

Javascript: How to get the value from a checked radio button when more than one radio button is present

From Dev

AngularJS, ngRepeat, and default checked radio button

From Dev

Ruby on rails - How to display different radio buttons once another radio button is checked?

From Dev

How to get value of checked radio?

From Dev

Android - How to enable a button if a radio button is checked?

From Dev

Getting value of checked radio button by name of radio button?

From Dev

Using the radio button 'checked' value in HTML and PHP

From Dev

javascript radio button return previous checked value

Related Related

  1. 1

    How to display checked value for radio button collection

  2. 2

    How to display checked radio button based on previous value?

  3. 3

    How to add checked class to a radio button in AngularJS

  4. 4

    How to set radio button checked initially in AngularJs?

  5. 5

    How to add checked class to a radio button in AngularJS

  6. 6

    How to get radio button checked in AngularJS?

  7. 7

    how to get checked radio button value in javascript

  8. 8

    Display radio button checked if json value is match to condition

  9. 9

    if radio button checked display div

  10. 10

    AngularJS Change Checked Value of Radio Button Using $scope variable

  11. 11

    How to get the value of the checked radio button and the remaining td's but not include the radio button that has not been checked (in tr)

  12. 12

    If radio button checked submit value?

  13. 13

    How to get value of selected radio button in angularjs

  14. 14

    How to get radio button value in SweetAlert with AngularJS

  15. 15

    How to reset Spinner value to "Select by something" based on Radio Button checked

  16. 16

    How to retrieve radio button value from database in checked state in jsp

  17. 17

    How to send the checked radio button value to Server in angular js

  18. 18

    How can i keep the radio button checked and get the value

  19. 19

    How to set checked="checked" in first radio button?

  20. 20

    Image Radio Button Checked Display Issues

  21. 21

    if radio button is checked, display divs and textbox

  22. 22

    Javascript: How to get the value from a checked radio button when more than one radio button is present

  23. 23

    AngularJS, ngRepeat, and default checked radio button

  24. 24

    Ruby on rails - How to display different radio buttons once another radio button is checked?

  25. 25

    How to get value of checked radio?

  26. 26

    Android - How to enable a button if a radio button is checked?

  27. 27

    Getting value of checked radio button by name of radio button?

  28. 28

    Using the radio button 'checked' value in HTML and PHP

  29. 29

    javascript radio button return previous checked value

HotTag

Archive