I have created a custom pipe to sort the array of objects but the pipe is not working ? my array of [ {name , population , variable }] . i want to sort the array of object according to population
PIPE:
import {Pipe , PipeTransform } from '@angular/core';
@Pipe ({
name:'order'
})
export class OrderByPipe implements PipeTransform{
transform(value: any[], property: any, descending?: boolean): any {
if (!value || value.length) {
return value;
}
value.sort((first: any, second: any): number => {
return first[property] > second[property] ? 1 : -1;
});
if (descending) {
return value.reverse();
}
return value;
}
}
HTML:
<ul>
<li *ngFor="let items of results"
{{items.name | order:'population':'true' }}
</li>
</ul>