NG-秀,即使条件满足时不工作 [英] ng-show not working even though condition is met

查看:163
本文介绍了NG-秀,即使条件满足时不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用NG-节目,它只是当事情存在,显示它。

I am trying to use ng-show and it is simply when something exists, display it.

<span ng-show="comment">{{comment}}</span>

我在作用域注释测试了这款=没有,但它隐藏它。当评论=是它显示了,我很困惑,为什么这是在JavaScript中发生的事情,因为我尝试,如果(评论)和它的作品...

I tested this in the scope comment="No" but it hides it. When comment="Yes" it displays it, I am confused why this is happening because in JavaScript I try if (comment) and it works...

推荐答案

NG-节目指令在内部使用的方法 toBoolean

ng-show directive internally uses a method toBoolean

下面是如何看起来像

function toBoolean(value) {
  if (value && value.length !== 0) {
    var v = lowercase("" + value);
    value = !(v == 'f' || v == '0' || v == 'false' || v == 'no' || v == 'n' || v == '[]');
  } else {
    value = false;
  }
  return value;
}

如果你看一下实现,什么都没有一样,假的,N,O值为false。

If you look at the implementation, anything like no, false,n,0 evaluate to false.

这篇关于NG-秀,即使条件满足时不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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