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

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

Setting Default Values in an Angular Reactive Form

How to Determine if a Column Exists in a DataReader

The Cause and Solution for the "System.Runtime.Serialization.InvalidDataContractException: Type 'System.Threading.Tasks.Task`1[YourTypeHere]' cannot be serialized." Exception

Loading an Image from an Embedded Resource in .NET