I have multiple ng-repeat
s which use a custom filter and I would like to hide the list. Each list has its own someScopeValue
value which is used to determine if a repeated item should be included (or filtered out).
My first attempt doesn't work and it's clear why not (items is only filtered in the ng-repeat
and ng-show
doesn't know about this:
<!-- this is clearly not smart logic -->
<ul ng-show="items.length">
<li ng-repeat="item in items | customFilter:someScopeValue">text</li>
</ul>
...
<ul ng-show="items.length">
<li ng-repeat="item in items | customFilter:someScopeValue">text</li>
</ul>
Is there a way to also apply the filter to the ng-show
? Here are some ideas I have but curious if there's a best practice or smarter way to do this:
<!-- this would filter the list somewhere in each <ul> scope -->
<ul ng-show="filteredList.length">
<li ng-repeat="item in filteredList">text</li>
</ul>
Or, maybe I can use ng-init
in some smarter way?
<!-- this filters the list on-the-fly for each <ul> using some scope function -->
<ul ng-init="filteredList = filter(items, someScopeValue)" ng-show="filteredList.length">
<li ng-repeat="item in filteredList">text</li>
</ul>