Angular if ng-repeat多重过滤器为空

时间:2015-02-23 22:27:47

标签: javascript angularjs filter angularjs-ng-repeat

假设我的ng-repeat中有多个过滤器,如下所示:

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 }}

现在,如果我最初没有things,那么我会收到这样的消息。但是,如果我过滤掉没有结果的东西,它就不会显示我理解的消息。

我的问题是,如何在集合或过滤器没有结果的情况下实现多重过滤器ng-repeat并显示消息?

我弄乱this example无济于事。我的尝试:

thing in filteredThings = thing | orderBy: 'name' | filter: search

1 个答案:

答案 0 :(得分:2)

你很亲密,语法有点偏离:

(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.