6

It seems that Angularjs ng-show directive interprets the 'N' and 'NO' as falsy values.

In my angular application, I'm displaying data related to a specific country using the following <div ng-show="countryCode">some code</div> I was surprised when I figured out that data related to Norway are not shown. And this is because the country code of Norway is 'NO' which is considered as falsy value !!

I don't know if this is a design choice. but if Yes how you deal with this kind of issues

You can reproduce this here

Thank you in advance

med
  • 323
  • 4
  • 11
  • 1
    Actually it's a design choice, you can see the responsible function here : https://github.com/angular/angular.js/blob/fca7bcaf43af3a4501ea0727d48f606c58d76bcd/src/Angular.js#L961 – DotDotDot Oct 28 '13 at 13:43

1 Answers1

3

Use ng-show="!!countryCode" to force the behaviour you want.


From reading the code, the behaviour appears to be by design. However, the documentation says:

if the expression is truthy then the element is shown or hidden respectively

which is only true if the angular developers are using truthy to mean something different to its javascript meaning.

JoeG
  • 12,994
  • 1
  • 38
  • 63