ng-show和ng-hide有什么区别? [英] What's the difference between `ng-show` and `ng-hide`?
问题描述
这些属性都被赋予true
或false
值,所以它们之间有什么区别?如果没有它们的价值,那将是有道理的.
These attributes are both given either a true
or false
value, so what difference is there between them? It would make sense if there weren't values for them.
我想念什么吗?
推荐答案
在我之前从事的项目中,我发现同时选择ng-show
和ng-hide
很有用.原因是因为我的导航栏中有一个链接,该链接仅应显示用户是否在特定视图上.这是这种情况:
On a project I was working on before, I found having the option of both ng-show
and ng-hide
useful. The reason being is because I had a link in my navbar that was only supposed to show if the user was on a specific view. Here is that scenario:
<li ng-hide="isActive('/about') || isActive('/contact')" ng-class="{ 'vert-nav-active': isActive('/investigator')}" class="top-buffer">
<a href="#/investigator" class="buff-sides navListLinks">Investigator Portal</a>
</li>
现在,您可能会说,好吧,您可以使isActive('/about') || isActive('/contact')
返回相反的布尔值并将ng-hide
更改为ng-show
,所有内容都将保持不变,但是正如您所看到的,我也正在使用它函数确定我在哪个链接上.如果我颠倒了这个逻辑,那么看起来好像我在每个链接上,但我所连接的实际链接除外.允许我可以为ng-show
编写另一个函数,但是我喜欢重用已经存在的代码.
Now, you might say, well you could just make the isActive('/about') || isActive('/contact')
return the opposite Boolean and change the ng-hide
to ng-show
and every thing will stay the same but as you can see I'm also using this function to determine which link I'm on. If I reverse this logic, it will look like I'm on every link except the actual link I'm on. Granted I could write another function for the ng-show
but I like reusing code that's already there.
这篇关于ng-show和ng-hide有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!