我有一个像下面的fliter一样的ng-repeat,
HTML
<li ng-repeat="article_data in articles | ArticleFilter:sfilter">
{{article_data.article_title}}
</li>
的Javascript
ey.filter('ArticleFilter', function(){
return function(items, filters){
var arrayToReturn = [];
if(value.article_title.toLowerCase().indexOf(filters.search_text.toLowerCase())==0)
arrayToReturn.push(value);
return arrayToReturn;
}})
我需要检查结果是否为空,并显示一条消息。是否可以这样做?我尝试了{{articles.length}}
,但这不是过滤结果的长度。
答案 0 :(得分:1)
尝试这样的事情,
<li ng-repeat="article_data in articles | ArticleFilter:sfilter as filteredResults">
{{article_data.article_title}}
</li>
{{ filteredResults.length }}
所以你可以拥有这样的代码,
<ul>
<li ng-repeat="article_data in articles | ArticleFilter:sfilter as filteredResults">
{{article_data.article_title}}
</li>
</ul>
<p ng-if='filteredResults.length === 0'> No results.</p>
另一种方式
<li ng-repeat="article_data in filteredResults = (articles | ArticleFilter:sfilter)">
{{article_data.article_title}}
</li>
<ul>
<li ng-repeat="article_data in filteredResults = (articles | ArticleFilter:sfilter)">
{{article_data.article_title}}
</li>
</ul>
<p ng-if='filteredResults.length === 0'> No results.</p>
PLUNK :http://plnkr.co/edit/01JZZzBBOSfrpcM4dbVR?p=preview
类似的问题,另一个演示:How to display length of filtered ng-repeat data