Reputation: 2181
I have defined my UI-Router states like this:
$stateProvider.state('contact', {
url: '/contactDemo',
views: {
'main': {
controller: 'contactMainController',
templateUrl: 'templates/contact.tpl.html'
}
}
}).state('contact.details', {
abstract: true,
controller: 'contactDetailsController',
templateUrl: 'templates/contact.details.tpl.html'
}).state('contact.details.add', {
url: '/add'
}).state('contact.details.filter', {
url: '/filter/{filterId}'
}).state('contact.details.filter.record', {
url: '/record/{recordId}',
resolve: {
record: ['$stateParams', 'Restangular', function($stateParams, Restangular) {
return Restangular.one('records', $stateParams.recordId).get();
}]
}
}).state('contact.details.filter.record.edit', {
url: '/edit'
});
Now I would like to inject my resolved record
into contactDetailsController
. If I do so, I get an Unknown provider
error. I can't move the resolve
into the abstract state, because from there I can't access the id inside $stateParams
.
If I move the controller
property down into the child state, my controller is never invoked.
Does anybody know how I can get the resolved property injected into the controller of an abstract parent state?
Upvotes: 1
Views: 1275
Reputation: 123901
As documented here, resolve could be inherited. NOT injected from child to parent.
New in version 0.2.0
Child states will inherit resolved dependencies from parent state(s), which they can overwrite. You can then inject resolved dependencies into the controllers and resolve functions of child states.
$stateProvider.state('parent', {
resolve:{
resA: function(){
return {'value': 'A'};
}
},
controller: function($scope, resA){
$scope.resA = resA.value;
}
})
.state('parent.child', {
resolve:{
resB: function(resA){
return {'value': resA.value + 'B'};
}
},
controller: function($scope, resA, resB){
$scope.resA2 = resA.value;
$scope.resB = resB.value;
}
Simply solution where:
$stateParam
is defined in the childresolve
dependent on it should be injected into parentcannot work - because one parent will be shared for many children.
Parent will stay while the children's params will differ..
Upvotes: 1