Mohsen Kashi Mohsen Kashi - 1 year ago 89
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download