如何使用“>" AngularJS ng-if语句中的比较器 [英] How to use ">" comparator in AngularJS ng-if statement
问题描述
是否可以在HTML的ng-if中使用大于"比较器? 问题在于>"符号会过早关闭HTML标记.
Is it possible to use the 'greater than' comparator in an ng-if in HTML? The problem is that the ">" symbol prematurely closes the HTML tag.
例如
这个:<div ng-if="foo>0" class="bar"> (HTML STUFF) </div>
读取为:<div ng-if="foo"> (0 class="bar"> HTML STUFF) </div>
我最终通过使用ng-if ="foo!= 0"解决了这个问题,但是我可能可以使用小于小于的比较器,但是我只是出于某种原因出于绝对原因不得不使用大于号的好奇.还是我可能必须将这种逻辑移到控制器中的其他地方而不是我的观点中?
I ended up getting around this by using ng-if="foo!=0" but I could probably use the less than comparator instead but I was just curious in case I absolutely HAD to use the greater than symbol for some reason. Or would I perhaps have to move this logic somewhere else like in my controller instead of in my view?
编辑1 因此,绝对可以认为比较器本身不是问题,而我的代码中还有其他问题.奇怪的是,当比较器前后有空格时,它可以工作,但没有空格时,它就没有.如果这有任何意义,我还将使用angular 1.3.15.
EDIT 1 So it definitely seems like the comparator itself isn't the problem and something else is going on in my code. Oddly, when I have spaces before and after the comparator it works but without spaces it doesn't. I'm also using angular 1.3.15 if that means anything.
<div class="paginate" ng-if="list.total > 0">
有效
<div class="paginate" ng-if="list.total>0">
不起作用
推荐答案
这是使用>
符号的示例.效果很好.
This is an example of using the >
symbol. This works fine.
<div ng-if="myvariable.length > 2">
</div>
这篇关于如何使用“>" AngularJS ng-if语句中的比较器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!