Savita Savita - 4 months ago 10
AngularJS Question

display jsonArray in angular js table format

I am getting response data as

array=[{"job id":"1",
"level 1":"er",
"level 2":"ED",
"level 3":"MT",
"status":"mt"
},
{"job id":"2",
"level 1":"ear",
"level 2":"ED",
"level 3":"MT",
"status":"mt"}
]


In above array there are 2 records retrieved from database and it may vary accordingly .

And I want to represent in Table format and column must be job id ,level 1, level 2 etc and values 1,ed, etc as in angular JS.

SSH SSH
Answer

Try use (key,value) in ng-repeat

var app=angular.module('app',[])
app.controller("Ctrl",function($scope,$filter){
   $scope.array=[
          {"job id":"1","level 1":"er","level 2":"ED","level 3":"MT","status":"mt"},
          {"job id":"2","level 1":"ear","level 2":"ED","level 3":"MT","status":"mt"}
     ]

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller=" Ctrl">
  <table border="1">
    <thead>
        <tr ng-repeat="(key,value) in array" ng-if="$last">
         <td ng-repeat="(key,v) in value">{{key}}</td>
      </tr>
    </thead>
       <tr ng-repeat="(key,value) in array">
         <td ng-repeat="(key,v) in value">{{v}}</td>
      </tr>
  </table>
</div>

Comments