I have a module with a factory inside it. This factory needs to be initialized ONCE when the program is booted and be passed an object.
Currently, I do this very none-elegantly. I include the module, and then in the run function of my main app.js, I call an initialization method of the factory and pass it the file:
/* The to be imported module */
angular
.module('myModule', [])
.factory('myFactory', function () {
var setting = null;
var myFactory = {
initialize : initialize,
action1 : action1,
...
};
return myFactory;
function initialize(obj) {
if (typeof setting == null) {
setting = obj;
}
}
});
/* Main app */
angular
.module('myApp', ['myModule'])
.app(function(myFactory) {
myFactory.initialize(someFile);
});
What's a more elegant way of doing this?