1

I'm new with angular ui router.

I have problems with loading settings from locally .json file.

I save the settings on app.run() in $rootscope.settings.

.run(['$rootScope', '$http', '$state', '$stateParams', function ($rootScope, $http, $state, $stateParams) {
    $rootScope.$state = $state;
    $rootScope.$stateParams = $stateParams;

    $http.get('./App/Core/Config/config.json').success(function (data) {
        $rootScope.settings = data;
    });

}])

before I go to $state I need a setting from $rootscope.settings to get data. But in the resolve the $rootscope.settings is underfined.

.state('alertcenter', {
            url: '',
            views: {
                'alertcenter': {
                    templateUrl: './App/Features/AlertCenter.html',
                    controller: 'AlertCenter'
                }
            },
            resolve: {
                Data: ['$http', function ($http) {
                    return $http({
                        method: 'GET',
                        url: $rootScope.settings.baseUrl + '/getData',
                        withCredentials: true
                    });
                }]
            }
        });

How can i access the settings in resolve of $state? Or is there another better way?

1
  • can you please put the code in plnkr? Commented Jan 27, 2015 at 7:49

1 Answer 1

5
resolve: {
                Data: ['$http','$rootScope', function ($http, $rootScope) {
                    return $http({
                        method: 'GET',
                        url: $rootScope.settings.baseUrl + '/getData',
                        withCredentials: true
                    });
                }]
            }

Try to inject $rootScope into resolve function first.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.