admin管理员组文章数量:1244387
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
本文标签: javascriptHow to declare enums in angularjsStack Overflow
版权声明:本文标题:javascript - How to declare enums in angularjs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740206777a2241235.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论