ng-show not working even though condition is met

雨燕双飞 提交于 2019-12-11 19:22:31

问题


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

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

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


回答1:


ng-show directive internally uses a method toBoolean

Here is how it looks like

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

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



来源:https://stackoverflow.com/questions/17745769/ng-show-not-working-even-though-condition-is-met

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!