Angular dynamic filter placeholder/fallback text? -


i'm attempting create placeholder text fallback dynamic filter, can not working , not sure if possible?

the filter code is:

*ngfor="let example of scale.examples | filter:{type: 'solo'} 

i able specify placeholder/fallback text if filter type not matched.

you can apply pipes anywhere. can this:

<div *ngif="(scale.examples | filter:{ 'type': 'solo' }).length === 0">no values</div> <div *ngfor="let example of scale.examples | filter:{ 'type': 'solo' }">    {{example.value}}  </div> 

here's working plunker: https://plnkr.co/edit/lxrrtdfl4di9qwjmx3wy?p=preview

update

if don't want overhead of sorting array twice can use new ngif else syntax:

<div *ngif="(myarr | filter:{ 'type': 'triple' }); let filteredarr" style="color: blue;">   <div *ngif="filteredarr.length === 0">no results</div>   <div *ngfor="let myobj of filteredarr" style="color: blue;">     {{myobj.value}}    </div> </div> 

here's working plunker: https://plnkr.co/edit/maipzwgz06vig1wnzdvw?p=preview

if want more elegant, it's best sort array on component side , use that.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -