I have a provider with an object I have for keeping track of a few things. I am having a problem when a I call a "new" for instantiating all the objects in the .config phase. So let me show you what I mean.
Here is my provider -
$moduleObjectProvider.$inject = [];
function $moduleObjectProvider() {
this.$get = $get;
$get.$inject = ['checkUrl', '$log', '$location'];
function $get( checkUrl, $log, $location) {
var modules = {};
//outer closure
function outerAddState(moduleObj) {
return function(stateName, stateOptions) {
//push new item into modules
}
}
return {
moduleConstructor: function(name, cb) {
if (modules[name]) {
//throw error
console.log(name + " module already exists.");
} else {
this.states = [];
this.callback = cb;
this.currentState = {};
this.addState = outerAddState(this);
modulePush(this, name);
}
},
modules: function() {
return modules;
}
}
}
}
And setting up the module like so
angular.
module('urlTesting', [])
.provider("$moduleObject", $moduleObjectProvider)
.config(function($moduleObjectProvider) {
var callback = function(name, obj) {
//console.log(name, obj);
}
//console.log($moduleObjectProvider.$get().moduleConstructor());
var mod = new $moduleObjectProvider.$get().moduleConstructor("module1", callback)
console.log(mod);
console.log($moduleObjectProvider.$get().modules());
})
SO - when I try to log that "mod" just to check the object, I get undefined. This USED to work fine, before I moved everything inside the $get - which I have to now do to inject necessary components into provider (not pretty, I know). I think I am doing something incorrectly now that I had to move everything inside the $get. Previously, I could do something like -
car mod = new $moduleObjectProvider.moduleConstructor("module1", callback)
However, now that I have put everything inside the $get, it doesn't seem to work. This one has me stumped, could use some help.
UPDATE: I think it has something ti do with the this.$get = $get; , because when I console.log the .modules - it returns everything, not just what should be inside module constructor. Seems like im making a new instance of the whole provider, not he constructor object.
edit2: It seems when I say "this" inside the module constructor, it is referring to both what is inside the current function (states, callback, etc) and what is outside as well(moduleconstructor, modules).
Thanks for reading!