2

I have a json like this

  {
    "0": {
        "Order_Id": "100000001",
        "prodct_Status": "Pending",
        "Price": "8.0000",
        "date_created": "Jun 4, 2014 7:55:42 AM",
        "Shipping_Address": "vbccv",
        "Region": "Arizona",
        "Country": "US"
    },
    "1": {
        "Order_Id": "100000002",
        "prodct_Status": "Pending",
        "Price": "38.4600",
        "date_created": "Jun 7, 2014 6:37:48 AM",
        "Shipping_Address": "vbccv",
        "Region": "Arizona",
        "Country": "US"
    },
    "2": {
        "Order_Id": "100000003",
        "prodct_Status": "Pending",
        "Price": "44.9200",
        "date_created": "Jun 10, 2014 4:52:46 AM",
        "Shipping_Address": "vbccv",
        "Region": "Arizona",
        "Country": "US"
    }
}

I wanna do ng repeat in this json . I have those 0 1 index there which i can not remove .

Ashisha Nautiyal
  • 1,389
  • 2
  • 19
  • 39

3 Answers3

3

you can use the standard ng-repeat syntax:

<body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <div ng-repeat="item in data">
      {{item.Order_Id}}
      {{item.Region}}
    </div>
  </body>

controller:

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';

  $scope.data = {
    "0": {
        "Order_Id": "100000001",
        "prodct_Status": "Pending",
        "Price": "8.0000",
        "date_created": "Jun 4, 2014 7:55:42 AM",
        "Shipping_Address": "vbccv",
        "Region": "Arizona",
        "Country": "US"
    },
    "1": {
        "Order_Id": "100000002",
        "prodct_Status": "Pending",
        "Price": "38.4600",
        "date_created": "Jun 7, 2014 6:37:48 AM",
        "Shipping_Address": "vbccv",
        "Region": "Arizona",
        "Country": "US"
    },
    "2": {
        "Order_Id": "100000003",
        "prodct_Status": "Pending",
        "Price": "44.9200",
        "date_created": "Jun 10, 2014 4:52:46 AM",
        "Shipping_Address": "vbccv",
        "Region": "Arizona",
        "Country": "US"
    }
   };

});

http://plnkr.co/edit/o7pQvhh2KKL7xgqhtL5L?p=preview

Marian Ban
  • 8,158
  • 1
  • 32
  • 45
  • 1
    `(key, item) in data` if you want access to the key as well: [(plunker)](http://plnkr.co/edit/spGLFCD1c22Ei4XuuMP4?p=preview) – Jason Goemaat Oct 06 '14 at 06:54
3

ng-repeat can iterate with objects as well:

<div ng-repeat="(index, order) in {'0':{'Order_Id':'1'},'1':{ 'Order_Id': '2'}}">
  <span>{{ order.Order_Id }}</span>
</div>

In your case string index can be ignored. See also this answer.

Community
  • 1
  • 1
Eugene Gluhotorenko
  • 3,094
  • 2
  • 33
  • 52
0

Try it like this

var json = { /* your json goes here */ };

<ul>
     <li ng-repeat="(key,value) in json">
      {{key}} {{value.Price}}
     </li>
</ul>

http://plnkr.co/edit/01vry4469ggGs1O1i5tI?p=preview

paka
  • 1,601
  • 22
  • 35