app/@overflow/commons/ui/pipe/array-sort.ts

18 lines
393 B
TypeScript
Raw Normal View History

2018-09-13 05:47:22 +00:00
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'sort' })
export class Sort implements PipeTransform {
transform(array: any[], field: string): any[] {
array.sort((a: any, b: any) => {
if (a[field] < b[field]) {
return -1;
} else if (a[field] > b[field]) {
return 1;
} else {
return 0;
}
});
return array;
}
}