Good morning, these days I'm facing an annoying problem. I need to be able to apply a sort on a list composed of Observable. The code I apply is as follows:
//Ascend
if (sortAscend) {
this.filteredVehicles$ = of(vehicleList).pipe(map(result => result.sort((a: any, b: any) => {
if (a[keyString] < b[keyString]) {
return -1;
} else if (a[keyString] > b[keyString]) {
return 1;
} else {
return 0;
}
})));
//Descend
} else {
this.filteredVehicles$ = of(vehicleList).pipe(map(result => result.sort((a: any, b: any) => {
if (a[keyString] > b[keyString]) {
return -1;
} else if (a[keyString] < b[keyString]) {
return 1;
} else {
return 0;
}
})));
}
but this triggers the ExpressionChangedAfterItHasBeenCheckedError error, going to change the data later. Is there a way I can avoid this?
Regards,
Emanuele