【问题标题】:Hiding parent div if filter renders child div empty in Angular如果过滤器在Angular中呈现子div为空,则隐藏父div
【发布时间】:2015-11-04 03:57:18
【问题描述】:

我找到了这个答案:AngularJS - hide parent element if children loop is empty (filtered),但它似乎对我不起作用。

我的代码完美运行,是:

    <div ng-repeat="lawyer in articlesByAuthor | orderObjectBy:'lastname':false" ng-show="sortType=='author'">
    <h3>{{lawyer.fullname}}</h3>
    <br/>
        <table border="1">
            <thead>
                <tr>
                    <th style="padding: 2px 5px;">
                    Date Published 
                    </th>
                    <th style="padding: 2px 5px;">
                    Article
                    </th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="article in lawyer | filter:searchArticle">
                    <td style="padding: 2px 5px;white-space:nowrap;">
                    {{article.date | date:'MMM. dd, yyyy'}}
                    </td>
                    <td style="padding: 2px 5px;;">
                    <a href="{{article.link}}" target="_blank" ng-if="article.link != ''"><span ng-bind-html="renderHtml(article.title)" class="articlePage"></span></a><span ng-bind-html="renderHtml(article.title)" class="articlePage" ng-if="article.link == ''"></span>
                    </td>
                </tr>
            </tbody>
        </table>
        <br/><br/>
    </div>

但是,如果搜索结果显示没有文章出现,我仍然会卡在一个空表,上面有名字。

基于上述,我尝试将整个东西包装在:

<div ng-show="(lawyer | filter:searchArticle).length">
</div>

无济于事。无论如何都不显示。我已经用articlearticlesByAuthor 替换了lawyer,但都不起作用。

我错过了什么?

【问题讨论】:

    标签: angularjs filter ng-show


    【解决方案1】:

    想通了。代码是正确的。我只是把它放在错误的地方。我需要将条件 ng-show 放在第一个 ng-repeat 内。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      相关资源
      最近更新 更多