I have this constructor function:
function State(url, templateUrl, controller, controllerAs, factory, resolveProp){
this.url = url
this.templateUrl = templateUrl
this.controller = controller
this.controllerAs = controllerAs
}
and in my router callback I have this:
$stateProvider
.state('archetypes', new State('/admin/archetypes', './resources/features/admin/archetypes/index.html', 'archetypes', 'aaVM'))
This works fine. I have another route, however, that contains a resolve to get some back end data.
I thought I might be able to do something like this for my constructor:
function State(url, templateUrl, controller, controllerAs, factory, resolveProp){
this.url = url
this.templateUrl = templateUrl
this.controller = controller
this.controllerAs = controllerAs
if(factory){
this.resolve = {}
this.resolve[resolveProp] = function(factory){
return factory.getAll()
}
}
}
and then instantiate a state in this way:
.state(
'archetypes',
new State(
'/admin/archetypes',
'./resources/features/admin/archetypes/index.html',
'archetypes',
'aaVM',
ArchetypesFactory,
'archetypes'
)
)
But I think the .state method calls the controller in order to process the resolve object, such that when I try the above state instantiation, it errors out because ArchetypesFactory is clearly undefined.
Note that when i write my state in this way:
.state('archetypes', {
url: '/admin/archetypes',
templateUrl: './resources/features/admin/archetypes/index.html',
controller: 'archetypes',
controllerAs: 'aaVM',
resolve: {
archetypes: function(ArchetypesFactory){
return archetypesFactory.getAll()
}
}
})
It works fine.
Is there any way I can abstract the state configuration object with a resolve into a constructor function or ES6 class?