How to Filter Out Objects With Empty Child Arrays When Using Angular's ngRepeat

Recently I was working on a website using Angular.js and needed to make use of the ngRepeat directive to iterate through a collection of objects. The UI in question needed to allow the user to select a child object, contained in an array, from one of the objects being displayed. And to provide a better user experience, I decided to only show those objects where the aforementioned array contained at least one object to select. Here's how I accomplished this using Angular's filtering capabilities, where elements is the name of the property containing the child objects to choose from:

<div ng-repeat="section in allSections | filter:{elements: []}:false">

Hopefully this will help someone trying to do something similar. :)

Comments

Popular Posts

Resolving the "n timer(s) still in the queue" Error In Angular Unit Tests

How to Get Norton Security Suite Firewall to Allow Remote Desktop Connections in Windows

How to Determine if a Column Exists in a DataReader

Fixing the "Please add a @Pipe/@Directive/@Component annotation" Error In An Angular App After Upgrading to webpack 4

Silent Renew and the "login_required" Error When Using oidc-client