1

Array

[
  code: 'code',
  specName: [
              0: 'First',
              1: 'Second',
              2: 'Third'
            ],
  year: [
              0: '2011',
              1: '2012',
              2: '2013'
            ]
];

The Lowdown

I am using AngularJS to output the data, using ng-repeat="name in module.specName". What I would like to do is link year[0] with specName[0] and so forth. So my output will look like:

 -------------------
| specName |  year  |
 -------------------
|  First   |   2011 |
 -------------------
|  Second  |   2012 |
 -------------------
|  Third   |   2013 |
 -------------------

Question

Could I be pointed in the right direction of how I could go about achieving this. Is there an angular .filter that I have to write or some data re-structuring in the angular app or something.

2 Answers 2

3
<div ng-repeat="(key,value) in data.specName">
    <span>{{value}}</span>
    <span>{{data.year[key]}}</span>         
</div>

JS:

$scope.data={
    code: 'code',
    specName: {
        0: 'First',
        1: 'Second',
        2: 'Third'
    },
    year: {
        0: '2011',
        1: '2012',
        2: '2013'
    }
};
Sign up to request clarification or add additional context in comments.

1 Comment

ah thank you! didn't know about (key, value) pairings in ng-repeat
2

If you're able to restructure your data like this:

$scope.data = {
  code: 'code',
  specs: [
     {name: 'First', year:2011 },
     {name: 'Second', year:2012 },
     {name: 'Third', year:2013 }
  ]
};

So you'll be able to display it very easy:

 <table>
     <tr ng-repeat="spec in data.specs">
        <td>{{spec.name}}</td>
        <td>{{spec.year}}</td>  
      </tr>
 </table>

Working example: http://plnkr.co/edit/Ka8jM8?p=preview

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.