I have based on this example to sort the columns of a table: Sort Table Colums
This is the code pipe:
import {Pipe, PipeTransform} from 'angular2/core';
@Pipe({ name: 'orderBy' })
export class OrderrByPipe implements PipeTransform {
transform(records: Array<any>, args?: any): any {
return records.sort(function(a, b){
if(a[args.property] < b[args.property]){
return -1 * args.direction;
}
else if( a[args.property] > b[args.property]){
return 1 * args.direction;
}
else{
return 0;
}
});
};
}
This is the html code:
<tr *ngFor="let particular of particulars | orderBy: {property: column, direction: direction} | slice:1; let i = index">
The import in the component:
import { OrderrByPipe } from '../pipes/orderby.pipe';
I want to migrate the pipe class to Angular 4, How could do it?
This is the error in console:
error_handler.js:60 Error: Uncaught (in promise): Error: Error in ./ParticularsListComponent class ParticularsListComponent - inline template:42:14 caused by: Cannot read property 'sort' of undefined
Error: Error in ./ParticularsListComponent class ParticularsListComponent - inline template:42:14 caused by: Cannot read property 'sort' of undefined
undefinedexactly). Could you check it please ?