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

Working on a TODO-app to learn Angular. I have this hardcoded array as a "database" and i want to display the tasks in the view.

var taskLists = [

    {name: 'Todays todo', id: '1', tasks:['Make coffe', 'another task']},
    {name: 'Tomorrow i will do this', id: '2', tasks:['Code well', 'go to bed']}

];

So how do i iterate through an array inside an array in an angular-view? I tried to have two ng-repeats but cant get it to work right. I want to display the tasks one by one as <td>, not just the whole tasks array as one <td> as it does right now ['Make coffe', 'another task']

This is what the view looks like.

<h2 ng-repeat="object in list">{{object.name}}</h2>
<table>
    <thead>
        <tr>Tasks</tr>
    </thead>
    <tr>
        <td ng-repeat="task in list">{{task.tasks}}</td>
    </tr>
</table>
share|improve this question
3  
you second ng-repeat shouldn't be ng-repeat="task in object.task" ? – Patrick Ferreira Jun 2 '14 at 14:30
1  
You were right, it should be task in object.tasks. Plus the HTML from the answer below did the trick. – Bullfinch Jun 2 '14 at 14:53
    
Oh yes, sure, the first repeat was only on the <h2> tag, i did not notice that :-) – Patrick Ferreira Jun 2 '14 at 14:55
up vote 2 down vote accepted

You have a problem in your logic.

Fist your HTML tag from child must be inside the parent.

<div class="parent" ng-repeat="object in list">
    <h2>{{object.name}}</h2>
    <table>
        <thead>
            <tr>Tasks</tr>
        </thead>
        <tr ng-repeat="task in object.tasks">
            <td>{{item}}</td>
        </tr>
    </table>
</div>

Try this and check if it works.

share|improve this answer
    
To have the second ng-repeat inside parent did the trick. Thank you! – Bullfinch Jun 2 '14 at 14:51

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.