前角pression内增量 [英] Increment inside angular expression
问题描述
我试图表现出一定的 DIV
S(这是3+ NG-重复
是S)和有条件然后增加一个计数器变量,。计数器有助于其决定的div的可见性的条件。
I am trying to show some div
s (which are under 3+ ng-repeat
s) conditionally and then increment a counter variable which. The counter contributes in the conditions which decide the visibility of divs.
当我做同样的事情到 NG-秀='富++< SOME_LIMIT
我得到一个语法错误:
When I do something similar tong-show='foo++ < SOME_LIMIT'
I get a syntax error:
Error: Syntax Error: Token 'undefined' not a primary expression at column NaN of the expression [moveItem.type != 'account' && team.rowCount++] starting at [moveItem.type != 'account' && team.rowCount++].
或
Error: Syntax Error: Token '2' is an unexpected token at column 42 of the expression [team.expandAccounts || team.rowCount++ < 2] starting at [2]
给code似乎并没有要求,但仍我给什么我尝试。
我想类似的东西:
Giving the code doesn't seem to be required but still I am giving what I was trying. I tried something similar to:
<div ng-repeat='request in pagedRequests'
<tr ng-repeat='(fooId, foo) in returnFoos(request)'>
<td ng-init='foo.rowCount = 0'>
{{foo.someAttribute}}
<!--Here is just an icon shown when the rowCount reaches some limit, say 3.
Uses ng-switch on foo.rowCount. Skipping this as this doesn't seem
problematic. This toggles rows' collapsing using foo.expandRows.-->
<div ng-repeat='bar in foo.bars'
ng-show='foo.rowCount < 3 || foo.expandRows'>
<span ng-show='bar.type=="multiRowBar"'
ng-repeat='row in bar.rows'>
<span ng-show="foo.expandRows || foo.rowCount++ < 3"> <!--SYNTAX ERROR!-->
<!--Showing the nested objects with more ng-repeats.-->
</span>
<span ng-show='bar.type!="multiRowBar" && foo.rowCount++<3'> <!--SYNTAX ERROR!-->
<!-- This adds a single row per bar of this type.-->
</span>
</div>
</td>
</tr>
</div>
难道我们不能使用POST / pre递增/递减运算符(如 ++
)内角前pressions?
Is it that we can't use post/pre increment/decrement operators (like ++
) inside angular expressions?
推荐答案
现在的问题是有点无知,这样的努力会触发循环 $消化
电话打破了事实。 (只是作出一些感觉出这个问题,我给我的解决方案中的缘故。希望这将有助于有人试图这东西)的解决方案,我最终确定参与压扁所有列表到一个列表,开关
ING显示图标 $指数
。
The question is a bit ignorant to the fact that such an effort triggers cyclic $digest
calls which breaks. (Just for the sake of making some sense out of this question I'm giving my solution. Hope it will help someone trying this stuff) The solution I finalized involved flattening all the lists to a single list and switch
ing to show the icon for a particular value of $index
.
这篇关于前角pression内增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!