Reputation: 117
I am trying to use a switch to control some image url parameters. My image.marketplace
node is a image.url.indexOf('?')
and evaluates to either -1
or a positive integer if a question mark is present in the url. I can get my expression (ng-switch on="{image.marketplace == -1}"
) to evaluate properly, but it does not trigger the correct "when" condition. Any thoughts about why?
<span ng-switch on="{image.marketplace == -1}">
<img ng-switch-when="true" ng-src="{{image.value}}?wid=100&hei=100">
<img ng-switch-when="false" ng-src="{{image.value}}&wid=100&hei=100">
<img ng-switch-default ng-src="{{image.value}}">
</span>
Upvotes: 2
Views: 4574
Reputation: 20401
The ngSwitchOn directive doesn't require curly brackets, as shown by the documentation. It's probably a better idea to make something like that :
<span ng-switch on="isMarketplaced(image)">
<img ng-switch-when="true" ng-src="{{image.value}}?wid=100&hei=100">
<img ng-switch-when="false" ng-src="{{image.value}}&wid=100&hei=100">
<img ng-switch-default ng-src="{{image.value}}">
</span>
And in the controller :
$scope.isMarketplaced = function (image)
{
return image.marketplace == -1;
}
In addition, it will help you to make unit tests on this function.
Upvotes: 3