ng-repeat with if else条件Angularjs(前端[HTML]部分) [英] ng-repeat with if else Conditions Angularjs (Front-End [HTML] part)
问题描述
寻找解决方案
实际数据
tier_price:
0:
price: "29.0000"
price_qty: 1
1:
price: "28.5000"
price_qty: 2
2:
price: "28.0000"
price_qty: 4
3:
price: "27.1500"
price_qty: 6
这是我的输入内容
price_qty = [1,2,4,6] 注意:数组是动态的
price_qty = [1,2,4,6] Note: Array is Dynamic
$ index = [0,1,2,3] 注意:索引取决于数组大小
$index = [0,1,2,3] Note: Index is depend on Array Size
count = 1起(通过单击按钮将手动增加)
count = 1 to onward (Will Manually increase by Click on Button)
注意:每次计数"增加时,以下代码将运行4次,例如[1,2,4,6]
Note: below code will run 4 times as each time Count increase e.g [1,2,4,6]
并且一旦条件进一步匹配,就不应再检查其他条件,例如 break 语句
And also Once Condition match it further should NOT check other conditions, kind of break statement
<div ng-repeat="tier in model.selected.tier_price">
<div ng-if="model.item.count == tier.price_qty">
Matching Items (This is working perfect)
</div>
<div ng-if="model.item.count < tier.price_qty && model.item.count == tier.price_qty+$index-3">
/** Facing issue at this place, Look like need to add One more
condition to achieve and don't know what should be the
condition because now if i use [model.item.count == tier.price_qty+$index-3]
Until Count==4 it work fine but when Count==5
then it wrong again because condition is not perfect**/
</div>
<div ng-if="model.item.count > tier.price_qty">
When Count is More than price_qty
</div>
</div>
以下是我实际上要实现的目标
below is what actually i want to achieve
买1买3买5
推荐答案
好了!首先,我很难理解您要达到的目标,因此我希望这接近于回答您.显示ng-repeat
元素并将其从给定表达式中隐藏的最灵活的答案是使用自定义的 filter .下面的代码显示了一个简单的示例.
Ok here goes! Firstly I had a hard time understanding what you were trying to achieve so I hope this comes close to answering you. The most flexible answer to showing ng-repeat
elements and hiding them from a given expression is through use of a custom filter. Code below shows a simple example.
还要查看文档和此
这篇关于ng-repeat with if else条件Angularjs(前端[HTML]部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!