Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm new Angular developer who needs help with ng-repeat. I have some complex json which i want to print in a table(<table>) or in orderd list (<ol>).

JSON

{
    "arrays": [
        [
            [1,2,3,4],
            [2,3,4,5],
            [3,4,5,6]
        ],
        [
            [1,2],
            [2,3],
            [4,5] 
        ] 
    ]
}

so, i have one array which contains n-arrays(2 in this example) and each of n-arrays contains the same number(3 in this example) of number-arrays. Each number-array of n-array part contains also the same number(first part of number-arrays has size 4 and the second part number-arrays has size 2)

And now i need something like that

#  |   Numbers
---------------------------------------
1  |   1     2    3    4    :    1    2
2  |   2     3    4    5    :    2    3
3  |   3     4    5    6    :    3    4

OR

1.    1    2    3    4    :    1    2
2.    2    3    4    5    :    2    3
3.    3    4    5    6    :    3    4
share|improve this question

Add a method to the controller to do the work for you.

controller

$scope.arrays = [
    [
        [1,2,3,4],
        [2,3,4,5],
        [3,4,5,6]
    ],
    [
        [1,2],
        [2,3],
        [4,5] 
    ] 
];

$scope.getRows = function () {
  var rows = [], i = 0;

  for (; i < $scope.arrays[0].length; i++) {
    rows.push($scope.arrays[0][i].concat(':', $scope.arrays[1][i]));
  } 

  return rows;
};

view

{{ getRows() | json }}
share|improve this answer
    
even if i retrun arrays from getRows function and print with {{getRows()}} nothing happend ..any solutions – nedroid Feb 7 '14 at 23:29
    
Do you have a Plunker or something? – reergymerej Feb 8 '14 at 0:21
    
No, but i have already figure it out. I had json in my variable so i had to access to array like this $scope.arrays.arrays[0]. It has also get printed in table, but besides that i'm getting error Error: [$rootScope:infdig] ...stackoverflow.com/questions/19369406/… ...do you now how to avoid that scope function ? – nedroid Feb 8 '14 at 7:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.