Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Just today I lost half an hour figuring out why my ng-show worked for all other strings except for "f" and "F". AngularJS definitely has it's own traps..


What is the trick? I usually use "!!variable" to ensure boolean conversion so I guess I would have been fine?


Yeah, "!!variable" works, and in my case I used ".length > 0". Boolean(variable) works too. It's just unfortunate when you're assuming that the expression or typecasting works like in JavaScript, and then AngularJS had to invent these unnecessary rules that make no sense. JavaScript's type coercion is tricky enough, you don't need to make it worse.


Any tool has.


But it would be good if the obvious way to do something didn't have certain magic conditions in which reasonable expectations aren't met (e.g. a variable is evaluated to its value, regardless of its name, or rather don't just change the language semantics in some places; yes I know it's fixed, still a good example), thereby minimizing those pitfalls.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: