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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -