-
Notifications
You must be signed in to change notification settings - Fork 27.4k
toBoolean returns false if "f" string is passed as argument. That prevents ng-show to evaluate to true when filtering text is "f" string #1229
Comments
The reason that ng-hide is working "differently" is that you are doing So the question is should this be fixed in angular, or is it just an edge case where your app needs to deal with it? I would argue the latter, and that this could probably be closed. Even if we tightened it up to not count "f" or "no" as falsy, your implementation would have troubles if someone searched for "false". And going all the way to saying that only One solution for you would be to create a new truthy variable using a $watch, like this: http://jsbin.com/oquhor/3/edit How's that? If you're happy can we close this issue: trying to get that big Thanks! |
Seems fine for me :) using a $watch can help and it is better to spend time fixing more serious issues than this one :) Lets close it. |
Thanks! 👍 On 30 January 2013 08:40, Tsvetan Tsvetkov [email protected] wrote:
|
The documentation includes a note on this (treating certain JS-truthy values as falsy), but I'm curious: why deviate from standard JS behavior here? |
@caitp I just saw the fix, I was curious for the historic justification :) |
…her one is entered alone. After the second letter has been entered, the results will be returned. Reason: 'f' will be interpreted as false and 'n' as null, which are both falsy. Further reference: http://stackoverflow.com/questions/18177522/why-ng-show-doesnt-work-when-f-or-n-is-typed angular/angular.js#1229 angular/angular.js#3436
I'm implementing a custom search field that consists of an text input element and a close icon that should appears when there is an entered text into the field. For that particular case i'm using ng-show to display the close icon.
Please see the example:
http://jsbin.com/oquhor/2/edit
Any string except "f", "false", "0", "n" and "no", shows the div element. But if i enter some of the mentioned strings the div element disapears. In other words when i start to type the word "false", when i type "f" letter the div will not be displayed, on typing "a" the div appears, and when i type the whole word "false" the div disappears again.
I took a look at the ng-show directive - it calls toBoolean function that returns false if the passed string is "f", "false", "n", "no" or "0". It is correct to accept "no" string for falsy value, but it is not correct from the javascript perspective where empty sting is evaluated to false, but any non-empty string is evaluated to "true".
I checked and if i use ng-hide instead of ng-show, everything works just fine. But it is supposed to get the same results in the both cases.
The text was updated successfully, but these errors were encountered: