order - AngularJs sort object in ngRepeat -


i'm using angularjs , found problem in ordering properties of hash object in template.
object like:

function testctrl($scope){     $scope.week = {'monday': ['manuel'], 'tuesday': [], 'wednesday': ['valerio'], 'thursday': ['manuel', 'valerio'], 'friday': []} } 

now, when try print these values in template:

<div ng-repeat="(day, names) in week">     <span>{{day}}</span>     <ul> <li ng-repeat="name in names">{{name}}</li> </ul> </div> 

the order of days printed different: friday monday thursday tuesday wednesday

i tried apply filter orderby think doesn't work objects, arrays...

how can order it?

as per angularjs docs (version 1.3.20):

you need aware javascript specification not define order return keys object. in order have guaranteed deterministic order keys, angular versions , including 1.3 sort keys alphabetically.

a workaround use array of keys:

function testctrl($scope){     $scope.week = {         'monday': ['manuel'], 'tuesday': [],          'wednesday': ['valerio'], 'thursday': ['manuel', 'valerio'],             'friday': []}      $scope.weekdays = ["monday", "tuesday", "wednesday", "thursday", "friday"]; } 

use array in view iteration:

<div ng-repeat="day in weekdays">     <span>{{day}}</span>     <ul> <li ng-repeat="name in week[day]">{{name}}</li> </ul> </div> 

update angularjs version 1.4.6 docs:

version 1.4 removed alphabetic sorting. rely on order returned browser when running for key in myobj.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -