In Angular.js templating, I need to test if a value is undefined or empty.... I am not sure how to do this since ng-switch-when
tests for expressions in strings. I
Following solution would also work (using angular 1.3.10):
<div ng-switch="selection">
<div ng-switch-default>The string is not empty!</div>
<div ng-switch-when="undefined">The string is empty!</div>
</div>
<div ng-switch="!!selection">
<div ng-switch-when="false">Empty, Null or undefined</div>
<div ng-switch-when="true">The string is not empty</div>
</div>
ng-switch allows expressions, you can use placeholder, as such:
<div ng-switch="selection || '_undefined_'" >
<span ng-switch-when="_undefined_">I am set to zero or undefined?!</span>
<span ng-switch-default>This string is not empty</span>
</div>
For more info: ng-switch on empty string
You usually do it within controller(see answer#1 in linked thread).