javascript - ng-repeat 中的 Angular 过滤器——没有匹配结果时显示消息

标签 javascript angularjs

我已经进行了过滤,可以根据用户的输入以及日期比较来过滤模型。我想在该过滤器未返回结果时显示一条消息。我已经看到了这个问题的其他答案,但我似乎无法让它们发挥作用。

这是我的 ng-repeat 设置方式:

<div ng-repeat="docs in casedocs | filter: filterDocuments | 
                orderBy: userSort : userSortDirection ">
                    <div style="float:left;padding-right:4px;" class="documentRadios">
                        <input type="radio" ng-model="docviews[0].docID" 
                               ng-show="typeOfLaw != 'CV'" value="{{docs.DocID}}" 
                               ng-change="loadDocument(1, 
                                          '{{docs.Description}}', {{docs.DocID}})" />
                        <input type="radio" ng-model="docviews[1].docID" 
                               ng-show="typeOfLaw != 'CV'" value="{{docs.DocID}}" 
                               ng-change="loadDocument(2,  
                                           '{{docs.Description}}', {{docs.DocID}})" />
                    </div>
                    <div class="documentTitle">
                        <a href ng-click="loadDocument(1, 
                                          docs.Description, docs.Doc_ID)">
                          {{docs.Description}}
                        </a>&nbsp;
                        <span class="documentFilingDate">   
                            ({{docs.DocFilingDate}})
                        </span>
                    </div>
                    <div class="documentIcons">
                        <a href="docview/{{docs.DocID}}" target="_blank">
                           <span class="glyphicon glyphicon-new-window white smaller">
                           </span>
                        </a>
                        <span ng-show="docs.Image_Type_ID == 3" class="glyphicon 
                              glyphicon-search white smaller"></span>
                        <span ng-show="docs.Security_Level > 0" class="glyphicon 
                              glyphicon-lock white smaller"></span>
                        <span ng-show="docs.QC_Review_Status == 1" class="glyphicon 
                              glyphicon-ok white smaller"></span>
                    </div>

                    <div style="clear:both;"></div>
                </div>
                <div class="col-sm-8">
                    <span class="notFound white">{{noDocumentsMsg}}</span>
                </div>
            </div>

根据我发现的示例,我应该更改 ng-repeat 声明,如下所示:

<div ng-repeat="docs in casedocs = (doc | filter: filterDocuments) 
               | orderBy: userSort : userSortDirection ">

然后使用基于!casedocs.lengthng-show,但是当我添加这个时,所有过滤都会中断。我见过的例子没有 orderBy 语句。我在这里做错了什么?

Example of answer previously given:

最佳答案

假设您的数据位于 $scope.casedocs 中,请尝试:

<div ng-repeat="docs in filteredCasedocs = (casedocs | filter: filterDocuments | orderBy: userSort : userSortDirection)">
    <!-- your code -->
</div>
<div ng-show="!filteredCasedocs.length">None avaialble</div>

关于javascript - ng-repeat 中的 Angular 过滤器——没有匹配结果时显示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33680809/

相关文章:

javascript - Android_Studio 错误

javascript - 使用 Angular 的解析 : {}? 时链接 promise 的最佳方式是什么

javascript - Angular JS - NG-Repeat with filters and groupBy

asp.net - oauth token 共享多个应用程序

javascript - itemMoved 回调在 ng-sortable 库中不起作用

php - 从 localStorage 中添加选项值

javascript - Chrome 似乎不允许 window.print()

javascript - 从 ng-repeat 内部调用 angularjs 属性指令

javascript - AngularJS:在其 Controller 中访问指令的 DOM 元素

javascript - Angular-gettext 从 javascript 文件中提取注释