Reputation: 263
I have the data of objects like this:
var details = {
3:{
2015-3-17 : 1,
2015-3-18 : 0,
routelines: "PASAY - CAGAYAN",
tripcode: 3
},
4:{
2015-3-17 : 0
2015-3-18 : 4
routelines: "PASAY - CAVITE",
tripcode:4
},
}
Now I am planning to display them in table but I am not sure how to start since they are all objects. I want to achieve the output which looks like this:
tripcode | routlines | 2015-3-17 | 2015-3-18|
3 |PASAY - CAGAYAN | 1 | 0 |
4 |PASAY - CAVITE | 0 | 4 |
Is there someone know how to do it? I tried this but unfortunately it's not work.
<div ng-repeat="detail in details">
<div ng-repeat="(key, value) in detail">
{{key}} : {{value}}
</div>
</div>
Upvotes: 4
Views: 1442
Reputation: 20633
Make sure to format your data object correctly, some keys were missing quotes. Also details should be bound to $scope.
Try this:
function MyCtrl($scope) {
$scope.details = {
'3': {
tripcode: 3,
routelines: "PASAY - CAGAYAN",
'2015 - 3 - 17': 1,
'2015 - 3 - 18': 0
},
'4': {
tripcode: 4,
routelines: "PASAY - CAVITE",
'2015 - 3 - 17': 0,
'2015 - 3 - 18': 4
},
};
}
.header,
.items {
border-bottom: 1px solid #000;
width: 600px;
}
.header span,
.items span {
display: inline-block;
width: 120px;
border-right: 1px solid #000;
padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
<div ng-controller="MyCtrl">
<div ng-repeat="detail in details">
<div class="header" ng-show="$index == 0">
<span ng-repeat="(key, value) in detail">{{key}}</span>
</div>
<div class="items">
<span ng-repeat="(key, value) in detail">{{value}}</span>
</div>
</div>
</div>
</div>
Upvotes: 2
Reputation: 38713
You have missed $scope
please change var details
to $scope.details
Upvotes: 1