Skip to content

Instantly share code, notes, and snippets.

@jspdown
Created May 9, 2015 15:26
Show Gist options
  • Save jspdown/f18d8910a99a9065a29c to your computer and use it in GitHub Desktop.
Save jspdown/f18d8910a99a9065a29c to your computer and use it in GitHub Desktop.
ng-repeat keep order
<div ng-controller="example">
<div ng-repeat="key in notSorted(data)" ng-init="value = data[key]">
<pre>
key: {{key}}
value: {{value}}
</pre>
</div>
</div>
<script>
angular
.module('test', [])
.controller('example', ['$scope', function ($scope) {
$scope.data = {
'key4': 'data4',
'key1': 'data1',
'key3': 'data3',
'key2': 'data2',
'key5': 'data5'
};
$scope.notSorted = function(obj){
if (!obj) { return []; }
return Object.keys(obj);
}
}]);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment