1

Lets say I have multiple filters in my ng-repeat like so:

input.search(ng-model="filter", placeholder="Search...")

ul.list
  li(ng-if="things.length === 0") It looks like we don't have any things.
  li(ng-repeat="thing in things | orderBy:'name' | filter: search")
    span {{ thing.name }}

Right now, if I initially have no things, then I receive the message saying so. But if I filter by something which yields no results, it does not display the message, which I understand.

My question is, how do you implement a multi-filter ng-repeat and display a message when the collection or filter yields no results?

I was messing with this example to no avail. My attempt:

thing in filteredThings = thing | orderBy: 'name' | filter: search
Community
  • 1
  • 1
Seth
  • 10,198
  • 10
  • 45
  • 68

1 Answers1

2

You were close, syntax was a little off:

(ng-repeat="thing in filteredThings = (things | orderBy:'name' | filter: search"))

li(ng-if="filteredThings.length === 0") It looks like we don't have any things.
tymeJV
  • 103,943
  • 14
  • 161
  • 157
  • So my attempt failed miserably (example updated). I tried the above but am getting errors. The bigger question is where does `filteredThings` come from? `things` is a collection in scope, does `filteredThings` have to exist as well? Or is that created on the fly? – Seth Feb 23 '15 at 22:42
  • @Seth - It's created on the fly - what errors are you getting? – tymeJV Feb 23 '15 at 23:10
  • I put the close parenthesis outside the `ng-repeat` attribute... All's well in the cosmos. Thanks for your help! – Seth Feb 23 '15 at 23:35