angularjskey-valueng-filter

How can I filter by value in ng-repeat(key, value) and only display if the value is not null?


I have an object with multiple properties, and I want to filter out the properties that are empty. Most of the properties are not required, and can be null. I cannot figure how to make a filter for that.

<div class="hero-unit" ng-repeat="(key, value) in selectedItem | valueNotNull">
                            <span class="hero-title">{{key|insertSpaces}} : </span>     
                            <span class="hero-content">{{ value }}</span>

When the value of the property is null or empty I do not want to diplay the hero unit for that specific property. And still show the rest of the properties.


Solution

  • You can hide the empty values

    Try like this

    <div class="hero-unit" ng-repeat="(key, value) in selectedItem" ng-hide="!value">
                                <span class="hero-title">{{key|insertSpaces}} : </span>     
                                <span class="hero-content">{{ value }}</span>