AngularJs:NG-显示/ NG隐藏 [英] AngularJs: ng-show / ng-hide

查看:188
本文介绍了AngularJs:NG-显示/ NG隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示/使用 NG-节目 NG-隐藏功能所提供隐藏一些HTML AngularJS

I am trying to show / hide some HTML using the ng-show and ng-hide functions provided by AngularJS.

根据该文件,对于这些功能的使用情况分别如下:

According to the documentation, the respective usage for these functions are as follows:

ngHide - {EX pression} - 如果EX pression truthy则该元素被显示或隐藏的分别。
  ngShow - {EX pression} - 如果EX pression是truthy则该元素被显示或隐藏分别

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.

这适用于以下用例:

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

不过,我们应该用一个参数从一个对象作为前任pression那么 NG-隐藏 NG-秀给出正确的真正 / 价值,但价值并不总是这样的处理为布尔返回

However, should we use a parameter from an object as the expression then the ng-hide and ng-show are given the correct true/false value but the values are not treated as a boolean so always return 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>

这是不是一个错误或我不正确地这样做。

This is either a bug or I am not doing this correctly.

我找不到引用的对象作为参数前pressions,所以我希望任何人都更好地理解AngularJs任何相关信息,也许能帮帮我吗?

I cannot find any relative information on referencing object parameters as expressions so I was hoping anyone with a better understanding of AngularJs might be able to help me out?

推荐答案

foo.bar 引用不应该包含大括号:

The foo.bar reference should not contain the braces:

<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>

pressions 需要是花括号绑定,那里的角内指令没有。

Angular expressions need to be within the curly-brace bindings, where as Angular directives do not.

另请参阅理解角模板

这篇关于AngularJs:NG-显示/ NG隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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