Reputation: 1909
I'm trying to pass a previously-resolved result from a parent to a modal instance that is instantiated onEnter
, however the controller reports that it's an unknown provider:
Error: [$injector:unpr] Unknown provider: resolvedRouteProvider <- resolvedRoute
Is there another way to inject this value, or am I restricted to only calling services from onEnter
functions?
For reference, the error occurs when navigating to a state like the child below:
$stateProvider
.state('parent',
resolve:
resolvedRoute: (Restangular) -> Restangular.all('route')
)
.state('child',
parent: 'parent',
onEnter: ($modal) ->
$modal.open(
templateUrl: 'templates/modal.html',
controller: 'ModalCtrl'
)
)
The controller is super-simple at this point:
.controller('ModalCtrl', ($scope, $modalInstance, resolvedRoute) ->
$scope.object = {}
$scope.createObject = ->
resolvedRoute.all('objects').post({object: $scope.object})
)
Upvotes: 2
Views: 3636
Reputation: 2904
Check out this example which it shows how you can inject data that is resolved to the onEnter function https://github.com/angular-ui/ui-router/wiki
like so:
$stateProvider.state("contacts", {
template: '<h1>{{title}}</h1>',
resolve: { title: 'My Contacts' },
controller: function($scope, title){
$scope.title = 'My Contacts';
},
onEnter: function(title){
if(title){ ... do something ... }
},
onExit: function(title){
if(title){ ... do something ... }
}
})
Upvotes: 0
Reputation: 1909
It turns out that you just need to pass another resolve through to the modal as well, e.g.
$stateProvider
.state('parent',
resolve:
parentResolve: (Restangular) -> Restangular.all('route')
)
.state('child',
parent: 'parent'
url: '/child'
resolve:
childResolve: (Restangular) -> Restangular.one('bar')
onEnter: ($modal) ->
$modal.open(
templateUrl: 'templates/modal.html',
controller: 'ModalCtrl'
resolve:
parentResolve: -> parentResolve
childResolve: -> childResolve
)
)
The ModalCtrl
will now have access to the parentResolve
and the childResolve
.
Please note: the resolves have to be returned from functions, so simply resolving the same object will not work.
resolve:
parentResolve: parentResolve
Upvotes: 4