0

I am using Angular js

after hit I got response below response how to loop it

one div name then value like this i want to loop

my response

{  
   "my2":[  
      {  
         "id":5,
         "cuid":20,
         "name":"my2",
         "month":"04",
         "created_at":"2018-04-01 00:00:00",
         "updated_at":"2018-04-11 00:00:00",
         "time":"04:32 PM",
         "status":"D"
      },
      {  
         "id":4,
         "cuid":20,
         "name":"my2",
         "month":"04",
         "created_at":"2018-04-02 00:00:00",
         "updated_at":"2018-04-12 00:00:00",
         "time":"12:10 PM",
         "status":"P"
      },
   ],
   "my":[  
      {  
         "id":44,
         "cuid":21,
         "name":"my",
         "month":"04",
         "created_at":"2018-04-12 00:00:00",
         "updated_at":"2018-04-12 00:00:00",
         "time":"09:08 PM",
         "status":"P"
      }
   ],
   "Testing":[  
      {  
         "id":43,
         "cuid":19,
         "name":"Testing",
         "month":"04",
         "created_at":"2018-04-12 00:00:00",
         "updated_at":"2018-04-12 00:00:00",
         "time":"09:05 PM",
         "status":"P"
      }
   ]
}

i try this

<div ng-repeat="data in reports" class="all_report">



           <div ng-repeat="data in reports">
{{reports.indexOf(data)}}
</div>
                <!--<div class="date">
                    {{data.created_at}} <br/>
                <span class="month">{{data.created_at}}</span>
                </div>
                <div class="status">{{data.status}}</div>-->
            </div>

but it not print anything how to print in div format

I don't know how to print

I tried above but not printing

how to achieve this to print in ng-repet?

My testing
  • 65
  • 2
  • 8

2 Answers2

1

You can use ng-repeat="(key, value) in reports" to iterate over the keys-value pairs in your reports object. For your specific case, the HTML would look something like the following:

<div ng-repeat="(key, value) in reports" class="all_report">
  <div>{{key}}</div>
  <div ng-repeat="data in value">
    <div>{{$index}}</div>
    <!-- Access data from the individual report rows here -->
  </div>
</div>
Jon Senchyna
  • 7,867
  • 2
  • 26
  • 46
0

look I can help you with your question, but it would be better if you write the answer you expect to see from JSON, to be able to accommodate HTML, but look at angularJS with ng-repeat helps you navigate the JSON, but as long as you have Well built the JSON, it suits you a bit the div, if it's really what you need. I leave a link where you can support

https://jptacek.com/2013/10/angularjs-introducing-ng-repeat/

$scope.test = {
   "my2":[
      {
         "id":5,
         "cuid":20,
         "name":"my2",
         "month":"04",
         "created_at":"2018-04-01 00:00:00",
         "updated_at":"2018-04-11 00:00:00",
         "time":"04:32 PM",
         "status":"D"
      },
      {
         "id":4,
         "cuid":20,
         "name":"my2",
         "month":"04",
         "created_at":"2018-04-02 00:00:00",
         "updated_at":"2018-04-12 00:00:00",
         "time":"12:10 PM",
         "status":"P"
      },
   ],
   "my":[
      {
         "id":44,
         "cuid":21,
         "name":"my",
         "month":"04",
         "created_at":"2018-04-12 00:00:00",
         "updated_at":"2018-04-12 00:00:00",
         "time":"09:08 PM",
         "status":"P"
      }
   ],
   "Testing":[
      {
         "id":43,
         "cuid":19,
         "name":"Testing",
         "month":"04",
         "created_at":"2018-04-12 00:00:00",
         "updated_at":"2018-04-12 00:00:00",
         "time":"09:05 PM",
         "status":"P"
      }
   ]
}

In HTML, something like that can go...

    <div ng-repeat="data in test" class="all_report">
            <div ng-repeat="x in data">
                    {{x}}
            </div>
     </div>
Dann
  • 23
  • 4