dman dman - 9 months ago 73
AngularJS Question

Angular.js ng-switch ---testing if value is empty or undefined

In Angular.js templating, I need to test if a value is undefined or empty.... I am not sure how to do this since

tests for expressions in strings. I needed to use
because it's a if else condition. Any ideas?

<div ng-switch="vipLabel">
<div ng-switch-when="vipLabel.toString()">
<h1>Getting sec</h1>
<div ng-switch-default>
<h3>Do you wish to unbind {{node.label}} from {{ vipLabel }}?</h3>


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>

For more info: ng-switch on empty string

You usually do it within controller(see answer#1 in linked thread).