In Angular2 I have an ngFor and want to orderby 1 field but without building a custom pipe.
Are there any built in ones I could use?
This is my code:
<tr *ngFor="let item of listOfMessages" [ngClass]="{unread: item.hasUnreadMessages}">
I want to order by item.hasUnreadMessages.
But I want the simplest way to do this.
I'm using html5 with angular2 and typescript
My attempt:
this.listOfMessages = this.listOfMessages.sort((item1:any, item2:any): boolean => this.compareByBool(item1, item2, "hasUnreadMessages"));
compareByBool = (item1: any, item2: any, fieldName: any): any =>{
return (item1[fieldName] === item2[fieldName] ? 0 : (item1[fieldName] ? -1 : 1));
}
If this is true: hasUnreadMessages then item should be at top of array