UI-Router
has different capabilities compared to Angular
's ngRoute
. It not only supports all the features of ngRoute
but also provides additional functionalities.
I am transitioning my Angular
application from ngRoute
to UI-Router
. However, I'm struggling with figuring out how to programmatically inject a resolve
function - a code snippet that I use outside of both the Controller
and config
.
In the case of standard Angular
's ngRoute
, I can dynamically inject my resolve promise
in the Angular
run block like this:
app.run(function ($route) {
var route = $route.routes['/'];
route.resolve = route.resolve || {};
route.resolve.getData = function(myService){return myService.getSomeData();};
});
Now, how can I achieve a similar injection of resolve promise using UI-Router
? I attempted to pass $stateProvider
for access to state
s, but encountered difficulties.
angular.module('uiRouterSample').run(
[ '$rootScope', '$state', '$stateProvider'
function ($rootScope, $state, $stateProvider) {
//$stateProvider would fail