I have an observable which I use in html with async
pipe and I want to sort it by label
at first, but don't understand how to do it correctly inside pipe. Label could be one of this 'High', 'Medium', 'Low'
, and also there is always first object with empty label, I should leave it on first place as it is, so if I receive array like this:
[
{name: 'ALWAYS FIRST', label: ''},
{name: 'test1', label: 'High'},
{name: 'test2', label: 'Low'},
{name: 'test3', label: 'Medium'},
{name: 'test4', label: 'High'},
...
]
I need to sort it like this
[
{name: 'ALWAYS FIRST', label: ''},
{name: 'test1', label: 'High'},
{name: 'test4', label: 'High'},
{name: 'test3', label: 'Medium'},
{name: 'test2', label: 'Low'},
...
]
Here's my code
html
<div *ngIf="photos$ | async as photos">
<div *ngFor="let photo of photos" class="photo-item">
{{photo.name}}
</div>
</div>
ts
photos$: Observable<Photos[]>;
ngOnInit() {
this.photos$ = this.store.select(selectPhotos)
.pipe(
?
);
}
Would be grateful for any help!