加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS:ng-show/ng-hide

发布时间:2020-12-17 09:26:35 所属栏目:安全 来源:网络整理
导读:我试图显示/隐藏一些HTML使用ng-show和ng-hide提供的功能 AngularJS 。 根据文档,这些功能的相应用法如下: ngHide – {expression} – If the expression truthy then the element is shown or hidden respectively. ngShow – {expression} – If the exp
我试图显示/隐藏一些HTML使用ng-show和ng-hide提供的功能 AngularJS

根据文档,这些功能的相应用法如下:

ngHide – {expression} – If the expression truthy then the element is shown or hidden respectively.
ngShow – {expression} – If the expression is truthy then the element is shown or hidden respectively.

这适用于以下usecase:

<p ng-hide="true">I'm hidden</p>
<p ng-show="true">I'm shown</p>

但是,如果我们使用来自对象的参数作为表达式,那么ng-hide和ng-show将被赋予正确的true / false值,但这些值不会被视为布尔值,因此始终返回false:

资源

<p ng-hide="{{foo.bar}}">I could be shown,or I could be hidden</p>
<p ng-show="{{foo.bar}}">I could be shown,or I could be hidden</p>

结果

<p ng-hide="true">I should be hidden but I'm actually shown</p>
<p ng-show="true">I should be shown but I'm actually hidden</p>

这是一个错误或我没有这样做正确。

我找不到任何相关的信息引用对象参数作为表达式,所以我希望任何人更好地了解AngularJS可能能够帮助我吗?

foo.bar引用不应包含大括号:
<p ng-hide="foo.bar">I could be shown,or I could be hidden</p>
<p ng-show="foo.bar">I could be shown,or I could be hidden</p>

角度expressions需要在卷曲括号绑定,其中作为Angular directives不。

参见Understanding Angular Templates。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读