json - Retrieving the keys in the insertion order with ng-repeat -
i have json string assigned angular model , used loop through , display key , value on ui .
<tr ng-repeat="(key,value) in profile> <td>{{key}} :</td> <td>{{value}}</td> </tr>
this works except order of keys not same model or model looks below
"profile": { "userid": 1234, "user name": "somename", "email address": "someone@yahoo.com", "age": 29, "occupation": "" }
the out put , in same order json string , how can achieve it?
age :29 email address : someone@yahoo.com occupation : userid : 1234 user name : somename
your need workaround objects unordered, described in question:
here workaround expressed example:
or jsfiddle:
html
<div ng-controller="myctrl"> <table> <tr ng-repeat="key in keys(profile)"> <td>{{key}}: {{profile[key]}}</tr> </table> </div>
javascript
var myapp = angular.module('myapp', []); myapp.controller('myctrl', function ($scope) { $scope.keys = function(obj){return obj? object.keys(obj) : [];} $scope.profile = { "userid": 1234, "user name": "somename", "email address": "someone@yahoo.com", "age": 29, "occupation": "" }; });
Comments
Post a Comment