How to name radio button values inside a radio button group in AngularJS?

123 Views Asked by At

So I have a form with many of the questions that are in a radio button group. My problem is that I want to name each of the values depending on the server's response. My code is as follows.

<div ng-repeat="item in qc.questions track by $index"  type={{item.type}}>
      <br> <b>Q)</b> {{item.question_text}}<br><br>

     <md-radio-group ng-model="qc.formData[answer][$index]" ng-if="item.type==='radio'||!item.type" >
        <div ng-repeat="answer in item.answers track by $index">
      <md-radio-button value="answer{{$index}}" class="md-primary">{{answer}}</md-radio-button>
        </div>
    </md-radio-group>

    <div ng-repeat="answer in item.answers track by $index" ng-if="item.type==='checkbox'||!item.type">
    <md-checkbox ng-model="qc.formData[answer]" >
            {{answer}}
    </md-checkbox>
    </div>
</div>

With this code I am able to set the values of the data with value="answer{{$index}}" and it sets values of the radio buttons as intended. But i would like to name each one of the values depending on the server response too, I am not able to do that. Right now the name starts from 0 and goes up to how many radio buttons there are. For example 0:"Ans2",1:"Ans2",3:"Ans1",3:"Ans4". I want to name and replace those numbers with something i get from the server like "Q1":"Ans2","Q2":"Ans2","Q3":"Ans1","Q4":"Ans4". How can I achieve this? Any help would be appreciated. Thanks!!

0

There are 0 best solutions below