Question

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

$scope.school{
  name  : "stackoverflow",
  sub   :{
    firstlang : "kannada"
  }
}

Here is my ng-repeat:

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

The desired result is: first language is = kannada

Was it helpful?

Solution

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: http://jsfiddle.net/pkozlowski_opensource/WXsFD/1/

<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: http://jsfiddle.net/pkozlowski_opensource/WXsFD/2/

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top