在NG-重复变量设置不被创建 [英] Variable set in ng-repeat not being created

查看:116
本文介绍了在NG-重复变量设置不被创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着<一个href=\"http://stackoverflow.com/questions/26218823/determining-how-many-results-are-shown-by-ng-repeat-filter\">this关于如何确定过滤掉元素数量的问题,我创建了以下角度code:

Following this question on how to determine number of filtered out elements, I created the following angular code:

<input type="text" ng-model="query" placeholder="Enter query...">
<div ng-if="filteredData.length!=data.length"> Showing {{filteredData.length}} of {{data.length}}</div>
<div ng-repeat="datum in filteredData = (data | orderBy: 'name' : reverse | filter:query)"> 
    ....
</div>

总是出现10然而,出于某种原因, filteredData 从来没有真正被设置和显示。我用回答得到的范围变量我的控制器,但 filteredData 不会不顾一切显示出来的其他变量有露面。

However, for some reason filteredData never actually gets set and Showing of 10 always appears. I used this answer to get the scope variable for my controller, but filteredData doesn't show up there despite all the other variables showing up.

另外值得注意:的重复做工精细的内容,它只是 filteredData 的心不是被设置

Also worth noting: the contents of the repeat work fine, its just that filteredData that isnt being set.

推荐答案

我相信这是因为你想你的NG-重复中设置filteredData。

I believe this is because you are trying to set filteredData within your ng-repeat.

您也许应该设置filteredData是一个过滤的控制器的数据。这样,你只是在循环重复的声明。

You should probably be setting filteredData to be a filtered set of your data in the controller. That way you are just looping in your repeat statement.

<div ng-repeat="datum in filteredData | orderBy: 'name' : reverse | filter:query"> 
    ....
</div>

这可能也是值得注意的是,NG-重复角滤波器不会编辑数组的长度。因此,在你的code居然没工作filteredData.length不会改变这种情况。

It's also probably worth noting that angular filter in ng-repeat wont edit your array's length. So in the case that your code actually DID work the filteredData.length wouldn't change.

这篇关于在NG-重复变量设置不被创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆