Created
May 9, 2015 15:26
-
-
Save jspdown/f18d8910a99a9065a29c to your computer and use it in GitHub Desktop.
ng-repeat keep order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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