Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 Use sort pipe only when certain value or boolean is true

My markup looks like this:

 <li *ngFor="let user of usersList | orderBy : ['name']; let i = index;">

So is there anyway to apply orderBy pipe only when certain boolean is true?

like image 702
CommonSenseCode Avatar asked Oct 19 '22 03:10

CommonSenseCode


1 Answers

How about something like

<li *ngFor="let user of usersList | orderBy : [value ? 'name' : '']; let i = index;">

Another option would be creating a wrapper pipe that takes a parameter and uses the orderBy pipe conditionally.

*EDIT

As @OliverRenner states, orderBy is no longer offered by Angular in 2.0. The above assumes that you have written your own orderBy implementation. See https://angular.io/docs/ts/latest/guide/pipes.html#!#no-filter-pipe

like image 161
Kevin Le Avatar answered Oct 21 '22 06:10

Kevin Le