Mohsen Kashi Mohsen Kashi - 3 months ago 27
AngularJS Question

AngularJS: Config $routeProvider after $http request

I need to config

after ajax request, but i can not using
in config, means following code causes error:

module.config(['$routeProvider','$http',function ($routeProvider,$http) {}

can not accessed in controller!

I need this approach for considering who can see what page as index page.


You can pass $routeProvider from config object to your controller. For example

in your route config file you write:

 .when('/', {
                    templateUrl: 'template.html',
                    controller: 'MyController',
                    controllerAs: 'main',
                    resolve: {
                        myRouteConfig: function(){
                            return $routeProvider;

and in controller you can inject it like a dependency

function MyController(myRouteConfig) {
   myRouteConfig.when ...... 

working example in fiddle