0

I need to display the key in the products AL200W401 (without xxxx) using ng-repeat. in my HTML code its displaying the AL200W401xxxx. How to go about this thanks.

JSON

{  
    "kits":"B11D0W201,AL200W401",
     "dateTo":"13/12/2016",
     "orders":[  
         {  
             "AL200W401":1,
             "B11D0W201":0,
             "date":"13 Dec 16"
         }
     ],
    "dateFrom":"12/12/2016",
    "products":[  
    {  
        "AL200W401":"AL200W401xxxx",
        "B11D0W201":"B11D0W201xxxx"
    }
    ]
}

HTML

<th ng-repeat="column in products">{{column}}</th> 
hd84335
  • 8,815
  • 5
  • 34
  • 45
June
  • 23
  • 7

3 Answers3

2

There is other similar questions where solution is sited. Check this for example

So you can do it this way:

<th ng-repeat="(key,value) in products[0]">{{key}}</th>

Please check this working demo: https://jsfiddle.net/hd84335/j0dr7bbp/

Community
  • 1
  • 1
hd84335
  • 8,815
  • 5
  • 34
  • 45
1
<th ng-repeat="(key,value) in products[0]">{{key}}</th> 
w.Bala
  • 129
  • 3
1

Working demo :

var myApp = angular.module('myApp',[]);

myApp.controller('MyCtrl',function ($scope) {
    $scope.jsonObj = {  
    "kits":"B11D0W201,AL200W401",
     "dateTo":"13/12/2016",
     "orders":[  
         {  
             "AL200W401":1,
             "B11D0W201":0,
             "date":"13 Dec 16"
         }
     ],
    "dateFrom":"12/12/2016",
    "products":[  
    {  
        "AL200W401":"AL200W401xxxx",
        "B11D0W201":"B11D0W201xxxx"
    }
    ]
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
 <div ng-repeat="(key,value) in jsonObj.products[0]">{{key}}</div>
</div>
Debug Diva
  • 26,058
  • 13
  • 70
  • 123