I'd like to declare some enums that should be globally accessed from anywhere in my application, eg:
enum AIState { Asleep, Idling, Chasing, Fleeing, HavingLunch };
Question: where and how do I have to declare those enums withint an angularjs
app?
main.js:
var myApp = angular.module('myApp', []);
myApp.config(...);
I later want to access them using AIState.Asleep
, so I could pass them as a parameter and delegate my logic accordingly.
I'd like to declare some enums that should be globally accessed from anywhere in my application, eg:
enum AIState { Asleep, Idling, Chasing, Fleeing, HavingLunch };
Question: where and how do I have to declare those enums withint an angularjs
app?
main.js:
var myApp = angular.module('myApp', []);
myApp.config(...);
I later want to access them using AIState.Asleep
, so I could pass them as a parameter and delegate my logic accordingly.
- Ok then what are remended ways of declaring the enum inside? – membersound Commented Jun 8, 2016 at 13:13
- Are you asking for a way to create a set of enum-like constants? JavaScript has no native enum facility. – Pointy Commented Jun 8, 2016 at 13:13
-
Yes, probably I'm asking this... from the
java
point of view. – membersound Commented Jun 8, 2016 at 13:15
1 Answer
Reset to default 12use constant
angular
.module('myApp', ['ngRoute'])
.constant("myConfig", {
"key": "value"
})
you can inject constant
as dependency and can use it
myApp.controller('myButton', ['myConfig', function(myConfig) {
var k = myConfig['key'];
});
Basically you can use constant
or value
.
some references
Constant
Value