AngularJS ng-if problems with 'f' and 'F'
ngIf
uses toBoolean
check internally. Here is toBoolean
itself:
function toBoolean(value) { if (typeof value === 'function') { value = true; } else if (value && value.length !== 0) { var v = lowercase("" + value); value = !(v == 'f' || v == '0' || v == 'false' || v == 'no' || v == 'n' || v == '[]'); } else { value = false; } return value;}
As you can see, there will be an issue not only with f
letter, but also with '0', 'no', 'n', etc. It's not going to be fixed though. However toBoolean
is likely to be removed in future versions.
See this discussion on Github: https://github.com/angular/angular.js/issues/1229?source=cc
I found simple solution to resolve my problem with validation by that:
<input type="text" ng-model="test" /><div ng-if="test.length > 0">TEST: {{test}}<div>
plunker: http://plnkr.co/edit/epDLYitkhCDMJJebfSON?p=preview
I prefer to use the double !!
notation to imitate how JavaScript normally works. This allows you to guard against test
being null.
<div ng-if="!!test">{{test}}<div>