praveenpds praveenpds - 1 month ago 22
AngularJS Question

AngularJS - ng-repeat is not working for inner properties

Here is an object that I'd like to use with ng-repeat, but it's not able to see the inner


name : "stackoverflow",
sub :{
firstlang : "kannada"

Here is my ng-repeat:

<li ng-repeat="index in school.sub">
first language is = {{index.firstlang}}

The desired result is:
first language is = kannada

Answer Source

Looking at your example it is not very clear how the school.sub data structure should look like in the end... Is it supposed to be an object (as in the example data structure) or an array (as you ngRepeat seems to suggest).

Provided that the school.sub is an object this would work:

<li ng-repeat="(key, value) in school.sub">first language is = {{value}}</li>

On the other hand, if you plan your sub structure to be an array the proper approach would be:

<li ng-repeat="index in school.sub">first language is = {{index.firstlang}}</li>

Hope that the above jsFiddles clarify how to approach both situations.