Angular orderBy: "timestamp" puts things in the wrong order

What I want to do:

Take an array of objects, each object with object.timestamp in milliseconds, and order them from the newest to the oldest.

Problem:

Angular orderBy doesn't seem to put things in the correct order. The following timestamps are entered in the following order:

  • 1416187808218 - // Nov/16/2014 5:30:PM 16/2014 // Nov/16/2014 5:30:PM
  • 1416187881192 - // Nov/16/2014 5:31:PM 16/2014 // Nov/16/2014 5:31:PM
  • 1416189118263 - // Nov/16/2014 5:51:PM 16/2014 // Nov/16/2014 5:51:PM
  • 1416189138827 - // Nov/16/2014 5:52:PM 16/2014 // Nov/16/2014 5:52:PM
  • 1416130064119 - // Nov/16/2014 1:27:AM 16/2014 // Nov/16/2014 1:27:AM

The correct / desired order is obviously equal to:

  • 1416189138827 - // Nov/16/2014 5:52:PM 16/2014 // Nov/16/2014 5:52:PM
  • 1416189118263 - // Nov/16/2014 5:51:PM 16/2014 // Nov/16/2014 5:51:PM
  • 1416187881192 - // Nov/16/2014 5:31:PM 16/2014 // Nov/16/2014 5:31:PM
  • 1416187808218 - // Nov/16/2014 5:30:PM 16/2014 // Nov/16/2014 5:30:PM
  • 1416130064119 - // Nov/16/2014 1:27:AM 16/2014 // Nov/16/2014 1:27:AM

So he goes 4, 3, 2, 1, 5 , when it should obviously be 1, 2, 3, 4, 5


Relative 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... ]; 
+5
source share
1 answer

Is your timestamp through your API as a string, not an integer? I understand that it looks good.

0
source

Source: https://habr.com/ru/post/1206995/


All Articles