Francis Empleo Francis Empleo - 10 months ago 83
AngularJS Question

cant access $parent.$index in scope

i can't display the value of ng-model in scope. "radiovalue[$parent.$index]" this piece of code does not return any values.
im getting the array from the php using angular


<div ng-repeat="question in set" ng-if = "question.type === 'multiple'">
<div class="shadow">
<li><div class="question">{{question.question}}</div></li>
<div id="multiple" ng-repeat="choice in question.questiontype.choice"><input type="radio" ng-name="question.type" ng-model="radiovalue[$parent.$index.choice]" ng-value="choice">{{choice}} </div>

$rootScope.radiovalue = [];

structure of the array
$json['questionid'] = $value['questionid'];
$json['question'] = $value['question'];
$json['type'] = $value['type'];
$json['questiontype']['choice']['a'] = $valueb['mc1'];
$json['questiontype']['choice']['b'] = $valueb['mc2'];
$json['questiontype']['choice']['c'] = $valueb['mc3'];
$json['questiontype']['choice']['d'] = $valueb['mc4'];

Guys new problem:
the output of array length is not correct. it displays array length of 5 although it has 2 defined array elements. i have here the plunker .

Answer Source

Should it not be:


And secondly you can get $parent.$index only when you have a ng-repeat inside a ng-repeat... i.e nested ng-repeat... then it makes sense.