angular 如何获取使用filter过滤后的ng-repeat的数据长度

Posted echo2016

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了angular 如何获取使用filter过滤后的ng-repeat的数据长度相关的知识,希望对你有一定的参考价值。

在做项目的过程中,被产品要求在内容为空的过程中显示提示信息,然哦户内容使用ng-repeat循环输出的,并且使用了filter过滤。后在谷歌上找到解决方案,如下:

?之前代码如下显示:

<ul>

<li ng-repeat="tagChoose in evaluateObj.tagChooseList|filter:{type:1}">

 <label> 

 <input type="checkbox" name="definedDic" ng-checked="checkedDicFile(tagChoose)"> 

 <span ng-bind="tagChoose.dicName"></<span se-mark="1">span> 

 </label> 

?</li>

?</ul>?

1.按需求改进代码(使用的angular版本1.3+):

?<ul> 

 <li ng-repeat="tagChoose in evaluateObj.tagChooseList|filter:{type:1} as localDics"> 

 <label ng-if="localDics.length>0"> 

 <input type="checkbox" name="definedDic" ng-checked="checkedDicFile(tagChoose)"> 

 <span ng-bind="tagChoose.dicName"></span> 

 </label> 

 <p class="help-block" ng-if="localDics.length==0">需要到词典管理界面添加自定义词典</p> 

 </li>

?</ul>

2.?按需求改进代码(使用的angular版本1.3-):

?<ul> 

 <li ng-repeat="tagChoose in localDics = (evaluateObj.tagChooseList|filter:{type:1})"> 

 <label ng-if="localDics.length>0"> 

 <input type="checkbox" name="definedDic" ng-checked="checkedDicFile(tagChoose)"> 

 <span ng-bind="tagChoose.dicName"></span> 

 </label> 

 <p class="help-block" ng-if="localDics.length==0">需要到词典管理界面添加自定义词典</p> 

 </li>

</ul>

以上是关于angular 如何获取使用filter过滤后的ng-repeat的数据长度的主要内容,如果未能解决你的问题,请参考以下文章