Francis Empleo Francis Empleo - 1 month ago 7
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

html:

<div ng-repeat="question in set" ng-if = "question.type === 'multiple'">
<div class="shadow">
<ul>
<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>
</ul>
</div>
</div>


Controller:
$rootScope.radiovalue = [];
console.log($rootScope.radiovalue);

PHP:
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 http://plnkr.co/edit/RfmK0s3FZIR0qziultEJ?p=preview .

Answer

Should it not be:

ng-model="radiovalue[$parent.$index].choice"

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.