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
The ng-show Directive in AngluarJS is used to show or hide the specified HTML element. If the given expression in the ng-show attribute is true then the HTML element will display otherwise it hides the HTML element. It is supported by all HTML elements.
The ngModel directive is a directive that is used to bind the values of the HTML controls (input, select, and textarea) or any custom form controls, and stores the required user value in a variable and we can use that variable whenever we require that value.
Q 10 - Which of the following is true about ng-show directive? A - ng-show directive can show a given control.
ng-show can show and hide the rendered data, that is, it always kept the rendered data and show or hide on the basis of that directives. ng-hide can show and hide the rendered data, that is, it always kept the rendered data and show or hide on the basis of that directives.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With