how can i use angularjs iterate a json string -


i have json string :

{"age":[459,918],"id":["bizno459","bizno459"],"name":["name459","wrongname459"]}

now want show using angular js :

<table>  <tr>    <th>column</th>    <th>value1</th>    <th>value2<th>  </tr>  <tr>    <td>age</td>    <td>459</td>    <td>918</td>  </tr>  <tr>    <td>id</td>    <td>bizno459</td>    <td>bizno459</td>  </tr>  </table>

the column dynamic, in example, there 3 : age, id, name. in example, have 2 columns: id,name.

how achieve this?

you can use json.parse convert json string object. after can use ng-repeat iterate on keys, , on each value every key:

function tablectrl($scope){    var jsonstring = '{"age":[459,918],"id":["bizno459","bizno459"],"name":["name459","wrongname459"]}';    $scope.data = json.parse(jsonstring);  }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>    <div ng-app>  <table ng-controller='tablectrl'>  <tr ng-repeat='(col, vals) in data'>    <td>{{col}}</td>    <td ng-repeat='val in vals track $index'>{{val}}</td>  </tr>  </table>    </div>


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -