我已经进行了过滤,可以根据用户的输入以及日期比较来过滤模型。我想在该过滤器未返回结果时显示一条消息。我已经看到了这个问题的其他答案,但我似乎无法让它们发挥作用。
这是我的 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>
<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.length
的ng-show
,但是当我添加这个时,所有过滤都会中断。我见过的例子没有 orderBy 语句。我在这里做错了什么?
最佳答案
假设您的数据位于 $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/