I'm using Angular and I want to check when a string is empty using ng-switch. The following code doesn't seem to be working for me.
<div ng-switch on="foo">
<span ng-switch-when="">This string is empty</span>
<span ng-switch-default>This string is not empty</span>
</div>
Any help with this would be appreciated.
<div ng-switch on="foo || 'null'">
<span ng-switch-when="null">This string is empty</span>
<span ng-switch-default>This string is not empty</span>
</div>
You will need to include the empty string in your controller:
function Ctrl($scope) {
$scope.items = ['', 'other'];
$scope.selection = $scope.items[0];
}
For additional reference, see the API: http://docs.angularjs.org/api/ng.directive:ngSwitch
Also, here's a working version of your code: http://jsfiddle.net/upPgU/