如何使用“>"AngularJS ng-if 语句中的比较器 [英] How to use ">" comparator in AngularJS ng-if statement
问题描述
是否可以在 HTML 的 ng-if 中使用大于"比较器?问题是>"符号过早地关闭了 HTML 标签.
例如.这个:
读作:
我最终通过使用 ng-if="foo!=0" 解决了这个问题,但我可能可以使用小于比较器,但我只是好奇,以防我出于某种原因绝对必须使用大于号.或者我是否可能需要将此逻辑移动到其他地方,例如在我的控制器中而不是在我的视图中?
编辑 1所以看起来比较器本身似乎不是问题,我的代码中还有其他问题.奇怪的是,当我在比较器前后有空格时,它可以工作,但没有空格就不行.如果这意味着什么,我也使用 angular 1.3.15.
这是一个使用 >
符号的例子.这工作正常.
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.
ex.
this: <div ng-if="foo>0" class="bar"> (HTML STUFF) </div>
is read as: <div ng-if="foo"> (0 class="bar"> HTML STUFF) </div>
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?
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">
works
<div class="paginate" ng-if="list.total>0">
does not work
This is an example of using the >
symbol. This works fine.
<div ng-if="myvariable.length > 2">
</div>
这篇关于如何使用“>"AngularJS ng-if 语句中的比较器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!