I'm currently utilizing the AngularJS $rootScope
object to expose some global constants that should be accessible to both controllers and views:
var app = angular.module('myApp', []);
app.run(function ($rootScope) {
$rootScope.myConstant = 2;
});
Rendering a global value in a view works correctly:
{{myConstant}}
Similarly, referencing the global value in an ng-if
condition also functions properly:
<span ng-if="someValue == myConstant">Conditional content</span>.
However, when trying to use the same value for comparison within an ng-switch
block, it never seems to evaluate to true. Check out this JSFiddle for a demonstration of my attempt to make this work. I have experimented with explicitly referencing the constant value as a member of $rootScope
and as an expression (inside double curly braces), but nothing seems to work.
Any insights into what I might be doing incorrectly?
Thank you,
Tim