如果在检查我的json
中的库存数量时显示正确in-stock (store) or (online)
消息的问题。如何正确检查ng中的条件是否使用操作员检查Angular2中的项目数量
所以情况是,如果库存不足10
其视为low-stock
如果如果大于10
然后in-stock
其0
然后out-of-stock
。
我的问题是当股价低于10
我*ngIf
认为价值0
以及因此它显示low-stock
以及out-of-stock
,或者如果股票10
它显示low-stock
和in-stock
。但如果股票大于10
其罚款。
如何正确检查股票以显示正确的股票消息?
样品JSON -
this.checkStock = {
"online": 0,
"store": 10
}
模板与ngIf
checks--
<p>
<span *ngIf="checkStock.online >= 10 "><i class="fa fa-check-circle fa-2x text-success" aria-hidden="true"></i> In-stock (Online)</span>
<span *ngIf="checkStock.online <= 10 "><i class="fa fa-exclamation-circle fa-2x text-warning" aria-hidden="true"></i> Low stock (Online)</span>
<span *ngIf="checkStock.online == 0"><i class="fa fa-times-circle fa-2x text-danger" aria-hidden="true"></i> Out-of-stock (Online)</span>
</p>
<p>
<span *ngIf="checkStock.store >= 10 "><i class="fa fa-check-circle fa-2x text-success" aria-hidden="true"></i> In-stock (store)</span>
<span *ngIf="checkStock.store <= 10 "><i class="fa fa-exclamation-circle fa-2x text-warning" aria-hidden="true"></i> Low stock (store)</span>
<span *ngIf="checkStock.store == 0"><i class="fa fa-times-circle fa-2x text-danger" aria-hidden="true"></i> Out-of-stock (store)</span>
</p>