Angularjs ng-show directive interprets "N" and "NO" as false values

The angularjs ng-show directive seems to interpret N and NO values ​​as falsification values.

In my angular app, I show country-specific data using the following <div ng-show="countryCode">some code</div> I was surprised to realize that the data related to Norway was not shown. And this is because the Norwegian country code is "NO", which is considered a false value !!

I do not know if this is a design choice. but if so, how do you deal with such problems?

Here you can play

Thank you in advance

+6
source share
1 answer

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


From reading code, the behavior looks by design. However, the documentation says:

if the expression is true, then the element is displayed or hidden accordingly

which is only true if angular developers use truthy to mean something other than its value in javascript.

+3
source

Source: https://habr.com/ru/post/956877/


All Articles