angularjs - orderBy not working in HTML divs -


i trying implement ng-repeat functionality divs. need sort data first (according rank has, provided object) , name div. creating custom orderby function . sorting functionality works well. however, getting order of divs same. (infact, opposite of need). tried using reverse functionalities, doesn't work.

my sorting code looks this:

var res = {                 "toyota": 2,         "ford": 1,         "chrysler": 4,         "hyundai": 3,         "nissan": 5 };  sortedval = object.keys(res).sort(function (a, b){     return res[a] - res[b]; }); 

my html div looks this,

<div class="card" ng-repeat="name in data | orderby: sortedval "> 

i correct output in console. however, divs arranged in order given below, no matter do.

nissan, chrysler, hyundai, toyota, ford.

i need them in order: ford, toyota, hyundai, chrysler, nissan.

note: don't worry "name in data" part, works well. having problems "orderby".

orderby either takes string object property or function defines order. no need calculate sortedval yourself, need give orderby method used calculate sortedval:

$scope.orderfn = function(a, b) {   return res[a] - res[b] }  <div ng-repeat="name in data | orderby: orderfn"></div> 

plunker: http://plnkr.co/edit/loeblx28wjav4rcvrxwq?p=preview


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -