0

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

4

1 に答える 1

5

ng-showディレクティブは内部的にメソッドを使用します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;
}

実装を見ると、no、false、n、0 などは false と評価されます。

于 2013-07-19T12:15:57.740 に答える