I have a result variable in angular component .ts file which holds the data returned from database . Now i have to filter the result variable to show only 20 records and date in ascending or descending order . I am very new to angular dont know too much how to filter this . Can you please give idea how this can he done .
let result;
switch (hoursType) {
case HoursType.workhours:
result = await this.service.getWorHours(this.username.value);
break;
case HoursType.Outofhourwork:
result = await this.service.getNonWork(this.username.value);
break;
}
CodePudding user response:
//to get 20 records
var myItems = result.slice(0, 20);
//to sort by date
myItems.sort((a, b) => {
return <any>new Date(b.date) - <any>new Date(a.date);
});