So I have a variable which could be of any type. By type I mean it could be a string, or an object. I'm trying to run different code depending on the type.
My variable is named range
, it's defined in the JavaScript. What I've tried is. vars
is an object which I'm looping through.
<tr ng-repeat="(key, range) in vars">
<td ng-switch="typeof range">
<span ng-switch-when="string">It's a string</span>
<span ng-switch-when="object">It's an object</span>
<span ng-switch-default>It's something else</span>
</td>
</tr>
but this will throw an invalid expression error. What's the best way to do this?
$scope.type = typeof $scope.range;
and in view<td ng-switch="type">
. Let me know if this helps.