简体   繁体   中英

Custom sort function in AngularJS

How to make a custom function to order?

I made this plunker , and noticed that I get an element at a time, which prevents me from ordering the elements of an array. Any idea?

I got to see these two issues, but none helped: angularjs custom sort function in ng-repeat e AngularJS: Custom Sorting Function using OrderBy

You need to return a value from your function that will be compared against the other values.

For example, it looks like in your plunkr you want to sort by birthday.

You might accomplish this with a function like so:

$scope.customSortFunc = function(person) {
   return new Date(person.birthday);
};

Keeping in mind that different browsers support parsing different date formats so ideally you'd use something like momentjs .

Example Plunkr

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM