NG-重复 - HTML内循环计数 [英] ng-repeat - count within html loop
本文介绍了NG-重复 - HTML内循环计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
反正是有指望一个项目,然后在循环外部显示呢?
Is there anyway to count an item, then display it outside of the loop?
<tr ng-repeat="value in values">
<td>value.total</td>
</tr>
<tr>
<td>Total Of All Values: {{ total }}</td>
</tr>
我已经使用 NG-的init()
来没有成功尝试,因为我觉得这是每一次压倒一切。
I've tried using ng-init()
to no success as I think it's over-riding each time.
<tr ng-repeat="value in values">
<td ng-init="total = total + value.total>value.total</td>
</tr>
<tr>
<td>Total Of All Values: {{ total }}</td>
</tr>
反正在这里做的,没有在我的控制器使一个功能?
Is there anyway of doing it here, without making a function in my controller?
推荐答案
总
这是在NG-重复初始化,将是一个不同的范围,不能被外部访问循环。
total
which is initialized in ng-repeat will be of a different scope and can not be accessed outside the loop.
试试这个:
<table ng-init="total = 0">
<tr ng-repeat="value in values">
<td ng-init="$parent.total = $parent.total + value.total">{{value.total}}</td>
</tr>
<tr>
<td>Total Of All Values: {{ total }}</td>
</tr>
</table>
这篇关于NG-重复 - HTML内循环计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文