user2663609
user2663609

Reputation: 427

value of json has to excape using ng-repeat

I have json file like

 { 
  "2014-08-01T23:00:00.000+05:30": { "In": 12, "Out": 23, "s1": 0 }
  "2014-08-01T22:00:00.000+06:00": { "In": 0, "Out": 0, "s2": 0 }
  "2014-08-01T22:00:00.000+06:30": { "In": 54, "Out": 0, "s3": 0 }
}

is it possible to ignore first index (ex:{2014-08-01T23:00:00.000+05:30,2014-08-01T22:00:00.000+06:00}..bcoz its varying timewise) attribute and access In and Out attribute using ng-repeat?

Upvotes: 0

Views: 47

Answers (2)

Umur Kontacı
Umur Kontacı

Reputation: 35478

You are trying to iterate over an object, not an array, the correct syntax is as follows.

(key, value) in expression – where key and value can be any user defined identifiers, and expression is the scope expression giving the collection to enumerate.

For example: (name, age) in {'adam':10, 'amalie':12}.

From https://docs.angularjs.org/api/ng/directive/ngRepeat

And in your case it would be,

<div ng-repeat="(key, value) in items">
    <span>In: {{ value.In }}, Out: {{ value.Out }}</span>
</div>

And {{ key }} will be the timestamp itself if you need it.

Upvotes: 1

Akhlesh
Akhlesh

Reputation: 2399

Yes it is possible.

//Json Data
$scope.data = { 
  "2014-08-01T23:00:00.000+05:30": { "In": 12, "Out": 23, "s1": 0 },
  "2014-08-01T22:00:00.000+06:00": { "In": 0, "Out": 0, "s2": 0 },
  "2014-08-01T22:00:00.000+06:30": { "In": 54, "Out": 0, "s3": 0 }
}


//html
<div ng-app="myapp" ng-controller="myController">
  <ul ng-repeat="d in data">
    <li>In: {{d.In}} Out: {{d.Out}}</li>
  </ul>
</div>

Fiddle Demo

Upvotes: 0

Related Questions