javascript - How to loop through the 'key' value of an object with AngularJS? -


i have following data , html template (and other code in app.js obviously). code in "tbody" works perfectly, , displays table this:

current output

-------------------- | aapl | 127 | 128 | -------------------- | goog | 523 | 522 | -------------------- | twtr |  35 |  36 | -------------------- 

now i'm trying loop through 'keys' of first object , display them in 'thead' so:

desired output

-------------------- | name | jan | feb | -------------------- | aapl | 127 | 128 | -------------------- | goog | 523 | 522 | -------------------- | twtr |  35 |  36 | -------------------- 

data

$scope.data = [ {       "name": "aapl",     "jan": "127",     "feb": "128" }, {     "name": "goog",     "jan": "523",     "feb": "522" }, {     "name": "twtr",     "jan": "35",     "feb": "36" }] 

html

<table>     <thead>         <tr>             <td ng-repeat="">{{}}</td>         </tr>     </thead>     <tbody>         <tr ng-repeat="object in data">             <td ng-repeat="(a,b) in object">{{b}}</td>         </tr>     </tbody> </table> 

it has been pointed out question duplicate of one, although, other 1 in plain js, 1 uses angularjs.

<td ng-if="data.length" ng-repeat="(a,b) in data[0]">{{a}}</td> 

you have consider key values appear in same order or table show values in wrong order.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -