2

I am trying to find tasks from a project and display them in separate div .

Following json string is my data source which is within {{projects}} variable.

[{"_id":"200566","value":[{"name":"Inbox","pinned":false,"milestone-id":"","description":"","uncompleted-count":0,"id":"713888","complete":false,"private":false,"position":3999,"status":"reopened","projectId":"200566","projectName":"fastfy.com","DLM":null},{"name":"General tasks","pinned":false,"milestone-id":"","description":"","uncompleted-count":6,"id":"673437","complete":false,"private":false,"position":4000,"status":"reopened","projectId":"200566","projectName":"fastfy.com","DLM":null}]},{"_id":"221840","value":[{"name":"Inbox","pinned":false,"milestone-id":"","description":"","uncompleted-count":0,"id":"800864","complete":false,"private":false,"position":3998,"status":"reopened","projectId":"221840","projectName":"The Crown","DLM":null},{"name":"General tasks","pinned":true,"milestone-id":"","description":"","uncompleted-count":3,"id":"751194","complete":false,"private":false,"position":4000,"status":"reopened","projectId":"221840","projectName":"The Crown","DLM":null}]},{"_id":"203859","value":[{"name":"General tasks","pinned":false,"milestone-id":"","description":"","uncompleted-count":3,"id":"690722","complete":false,"private":false,"position":4000,"status":"reopened","projectId":"203859","projectName":"mphosipalityconsulting.com","DLM":null}]},{"_id":"207043","value":[{"name":"General tasks","pinned":false,"milestone-id":"","description":"","uncompleted-count":1,"id":"700757","complete":false,"private":false,"position":4000,"status":"new","projectId":"207043","projectName":"Gloucester B&B & Pub","DLM":null}]}]

I have tried

        {{projects}}
        <li class="list-group-item" ng-repeat="p in projects">
            <div class="nm">
                {{p.value[$index].projectName}}
            </div>
            <div class="taskBtn">  
            <button type="button" class="btn btn-info" data-toggle="collapse" data-target="#taskList{{post.id}}">[+]</button>
            </div>
            <div id="taskList{{post.id}}" class="collapse">
                {{p.value[$index].name}}

            </div>              
        </li>

This outputs following

enter image description here

Could you tell me how do i get the looping properly and get Something like

Project name : Task lists :

project name : tasks lists:

Project name : Task lists :

project name : tasks lists:

1
  • Are the tasks in the "value" array? Commented Aug 17, 2016 at 16:23

2 Answers 2

2

Use ng-repeat inside an ng-repeat

Your DOM

<!DOCTYPE html>
<html ng-app="App">

  <head lang="en">
    <meta charset="utf-8">
    <title>Custom Plunker</title>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
    <link rel="stylesheet" href="style.css">
  </head>

  <body ng-controller="Proj">
    <ul ng-repeat="p in projects">     
      <ul>
        <li ng-repeat="item in p.value">
              {{item.name}}
        </li>
      </ul>
    </ul>
  </body>

</html>

Controller code:

angular.module('App', []).controller('Proj', function ($scope) {
    $scope.projects = [{"_id":"200566","value":[{"name":"Inbox","pinned":false,"milestone-id":"","description":"","uncompleted-count":0,"id":"713888","complete":false,"private":false,"position":3999,"status":"reopened","projectId":"200566","projectName":"fastfy.com","DLM":null},{"name":"General tasks","pinned":false,"milestone-id":"","description":"","uncompleted-count":6,"id":"673437","complete":false,"private":false,"position":4000,"status":"reopened","projectId":"200566","projectName":"fastfy.com","DLM":null}]},{"_id":"221840","value":[{"name":"Inbox","pinned":false,"milestone-id":"","description":"","uncompleted-count":0,"id":"800864","complete":false,"private":false,"position":3998,"status":"reopened","projectId":"221840","projectName":"The Crown","DLM":null},{"name":"General tasks","pinned":true,"milestone-id":"","description":"","uncompleted-count":3,"id":"751194","complete":false,"private":false,"position":4000,"status":"reopened","projectId":"221840","projectName":"The Crown","DLM":null}]},{"_id":"203859","value":[{"name":"General tasks","pinned":false,"milestone-id":"","description":"","uncompleted-count":3,"id":"690722","complete":false,"private":false,"position":4000,"status":"reopened","projectId":"203859","projectName":"mphosipalityconsulting.com","DLM":null}]},{"_id":"207043","value":[{"name":"General tasks","pinned":false,"milestone-id":"","description":"","uncompleted-count":1,"id":"700757","complete":false,"private":false,"position":4000,"status":"new","projectId":"207043","projectName":"Gloucester B&B & Pub","DLM":null}]}];;   
});

http://plnkr.co/edit/4RaxuzA3YXRIG8LvPwlr?p=preview

Sign up to request clarification or add additional context in comments.

1 Comment

You beat me to it.
0

This Nested ng-repeat can b your solution...

 <li class="list-group-item" ng-repeat="p in projects">
        <div class="nm">
            {{p.value[$index].projectName}}:
        <ul ng-repeat="t in p.value">
       <li>{{t.name}}</li>
        </ul>
        </div>
        <div class="taskBtn">  
        <button type="button" class="btn btn-info" data-toggle="collapse" data-target="#taskList{{post.id}}">[+]</button>
        </div>
        <div id="taskList{{post.id}}" class="collapse">
            {{p.value[$index].name}}

        </div>              
    </li>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.