What I want to do:
Take an array of objects, each object with object.timestamp
in milliseconds, and order them from newest to oldest.
The problem:
Angular's orderBy doesn't seem to be putting things in the correct order. The following timestamps are getting put in the following order:
- 1416187808218 -
// Nov/16/2014 5:30:PM
- 1416187881192 -
// Nov/16/2014 5:31:PM
- 1416189118263 -
// Nov/16/2014 5:51:PM
- 1416189138827 -
// Nov/16/2014 5:52:PM
- 1416130064119 -
// Nov/16/2014 1:27:AM
The correct/desired order is obviously be:
- 1416189138827 -
// Nov/16/2014 5:52:PM
- 1416189118263 -
// Nov/16/2014 5:51:PM
- 1416187881192 -
// Nov/16/2014 5:31:PM
- 1416187808218 -
// Nov/16/2014 5:30:PM
- 1416130064119 -
// Nov/16/2014 1:27:AM
So it's going 4, 3, 2, 1, 5
when it should be, obviously, 1, 2, 3, 4, 5
The relavent code:
html:
<div class="cardWrapper" ng-repeat="card in cards | orderBy:'timestamp'">
various child elements
</div>
javascript:
scope.cards = homeData.get().cards; // returns an array of objects
// ^this^ becomes something similar to
scope.cards = [
{text: 'some text...', timestamp: 1416189138827, other: 'data'},
{text: 'some text...', timestamp: 1416187881192, other: 'data'}
//etc...
];
Is your timestamp coming through your API as a string and not an integer? I realize here it looks fine.