2

i have a value inside $rootscope and i want to access this value inside the config function , this is my code :

--run function 
myApp.run(function ($rootScope) {

$rootScope.myVariable = "my value";

});


--config function



myApp.config(['$provide','$routeProvider','$stateProvider','$urlRouterProvider',function($provide,$routeProvider,$stateProvider,$urlRouterProvider) {

    // here ,i want to access to myVariable value to do some tests
        $urlRouterProvider.otherwise(function($injector){

            var $state = $injector.get('$state');
            var $rootScope = $injector.get('$rootScope');

               alert($rootScope.myVariable == "1");

            if ($rootScope.myVariable) {
                $state.go('mystat1'); 
            }
            else {
                 $state.go('mystat2');   
            }

        });

     }]);

any idea how to achieve this.

thanks in advance

James
  • 1,190
  • 5
  • 27
  • 52

1 Answers1

2

The .config block is exectuted before .run, try this run and config order.

Community
  • 1
  • 1
Itsik Mauyhas
  • 3,824
  • 14
  • 69
  • 114