1

I have an angular config for loading routes.

app.config(["$stateProvider", "$urlRouterProvider", 
    function ($stateProvider, $urlRouterProvider) {

        var states = [
            {
                name: "login",
                config: {
                    url: "/login",
                    pageTitle: "Login",
                    template: "<login></login>"
                }
            },
            {
                name: "app",
                config: {
                    url: "/app",
                    pageTitle: "Application",
                    template: "<app></app>"
                }
            }];

        states.forEach(function (state) {
            $stateProvider.state(state.name, state.config);
        });

        $urlRouterProvider.otherwise("/app/index");
    }])

But I want to load states from server. So I need to use $http provider, but it does not work in config.

barteloma
  • 6,403
  • 14
  • 79
  • 173

1 Answers1

0

What will work for this scenario is not $http in .config(), but .run() and $urlRouterProvider.deferIntercept();. There is a documentation (link and small extract)

deferIntercept(defer)

Disables (or enables) deferring location change interception.

If you wish to customize the behavior of syncing the URL (for example, if you wish to defer a transition but maintain the current URL), call this method at configuration time. Then, at run time, call $urlRouter.listen() after you have configured your own $locationChangeSuccess event handler.

There are more details and working plunker https://stackoverflow.com/a/29013914/1679310

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335