Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs ng-show directive interprets the 'N' and 'NO' as falsy values

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

like image 575
med Avatar asked Oct 28 '13 13:10

med


People also ask

What is Ng-show in AngularJS?

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.

What is NG model directive in AngularJS?

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.

Which of the following is true about ng-show directive?

Q 10 - Which of the following is true about ng-show directive? A - ng-show directive can show a given control.

What is Ng-show and Ng hide?

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.


1 Answers

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.

like image 118
JoeG Avatar answered Oct 30 '22 15:10

JoeG