我的一项服务中有一个枚举。
home.factory('myService', ['$dialogs', '$resource',
function ($dialogs, $resource) {
var myEnum= {
val1: 0,
val2: 1
};
return {
DoSomething : function (param1) {
...
}
};
}]);
当我在其他服务中调用方法时,我需要共享此枚举。 基本上需要将枚举作为参数发送到另一个服务中的其他方法。 这样做的最佳方法是什么?
答案 0 :(得分:4)
定义constant
:
app.constant('myEnum', {
val1: 0,
val2: 1
});
并将其注入其他服务:
app.service('myService', ['myEnum', function (myEnum) {
console.log(myEnum);
}]);
答案 1 :(得分:2)
从工厂返回枚举
home.factory('myService', ['$dialogs', '$resource', ,
function ($dialogs, $resource) {
return {
DoSomething : function (param1){
},
myEnum: {
val1: 0,
val2: 1
}
};
};
}]);
您可以通过
访问myService.myEnum;