Angular:DOM中的条件元素? [英] Angular: Conditional element in DOM?

查看:90
本文介绍了Angular:DOM中的条件元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AngularJS中,

只有当一个范围变量为真时,我才能使HTML存在?



我知道有 ng-show 指令,但这对我来说不起作用,因为它只会使 display:none ,但我需要的实际是该元素只在DOM中存在,当评估某事时。



类似这样的东西对我来说很有用:< div ng-exists =myvar == myothervar>< / div>

解决方案

您可以使用Angular的 ng-if 指令(请参阅

 < div ng-if =myvar == myothervar >< / DIV> 


In AngularJS,

how would I make a HTML exist only if a scope variable is true?

I know there is the ng-show directive but this will not work for me as it will only make it invisible with display: none, but what I need is actually that the element only exists in the DOM when something evaluates.

Something like this would work for me: <div ng-exists="myvar==myothervar"></div>

解决方案

You can use Angular's ng-if directive (see the docs):

<div ng-if="myvar==myothervar"></div>

这篇关于Angular:DOM中的条件元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆