我怎么只有嵌套纳克重复不是空的显示元素? [英] How do I only show an element if nested ng-repeat is not empty?

查看:131
本文介绍了我怎么只有嵌套纳克重复不是空的显示元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表的列表,以嵌套的NG-重复创建。每个外NG-重复包含其内部列表的标签的div(如:A组)。现在我试图创建一种方法来避免显示此标签,如果内部列表是空的,由于过滤(由输入SEARCHTEXT应用)

I have a List of lists, created with a nested ng-repeat. Each outer ng-repeat contains a div with the label of its inner list (eg: "Group A"). I'm now trying to create a way to avoid showing this label if the inner list is empty due to filtering(Applied by an input searchtext)

下面是一个plunker解释我的问题,我试图解决方案: Plnkr

Here is a plunker explaining my issue and my attempted solution : Plnkr

拥有一个像isGroupEmpty一个重功能似乎非常麻烦 - 有没有办法在一个更简单的方式做到这一点?我是用移动标签内NG重复里面有 NG-秀=$第一的想法玩弄但它不很好看

Having a 'heavy' function like isGroupEmpty seems extremely cumbersome - Is there any way to do this in a much simpler fashion? I was toying with the idea of moving the label inside the inner ng-repeat and having ng-show="$first" but it doesnt look great

推荐答案

我结束了以下解决方案,它完美地工作。 Plnkr

I ended up with the following solution which worked perfectly. Plnkr

通过在内部设置变量NG-重复我能够在此基础上的变量长度,像这样评价NG-显示:

By setting a variable in the inner ng-repeat I was able to evaluate ng-show based on this variables length like so :

<input ng-model='searchText'/>
<span ng-show='filtered.length > 0'>
  <ul>
    <li ng-repeat='el in filtered = (model | filter:searchText)'>
      <div>{{el.label}}</div>
    </li>
  </ul>
</span>

这篇关于我怎么只有嵌套纳克重复不是空的显示元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆