In my last question I did search a solution to use a value in AngularJS during .config. I learned I have to use a provider. Now I try to set a value using this provider. It seems there is a limitation with providers, I can set something ONLY during .config ? I get the error "TypeError: appState.setState is not a function", but setState is a function, at least for my understanding. I'm wrong?
The code:
angular
    .module('main', [
        'ngRoute'
    ])
    .provider('appState', function(){
        var appState;
        this.setState = function(newState) {
            appState = newState;
        };
        this.getState = function() {
            return appState;
        };
        this.$get = function() {
            return appState;
        };
        function init() {appState='/home';}
        init();
    })
    .config(function($routeProvider, appStateProvider){
        $routeProvider
            .when('/home', {
                templateUrl: "partials/home"
            })
            .when('/info', {
                templateUrl: "partials/info"
            })
            .otherwise({
                redirectTo: appStateProvider.getState()
            })
    })
    .run(function ($rootScope, appState) {
        $rootScope.$on('$routeChangeStart', function (event, next, current) {
            if (next.$$route) {
                appState.setState(next.originalPath); 
                // -> ERROR: "TypeError: appState.setState is not a function"
            }
        })
    })
;
 
     
    