2
我有$ rootscope內的值,我想訪問配置功能裏面這個值,這是我的代碼:
--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');
}
});
}]);
任何想法如何實現這個。
在此先感謝
可能的重複http://stackoverflow.com/questions/10486769/cannot-get-to-rootscope#10489658 – RamblinRose
那麼有什麼問題? –
運行塊在配置塊後執行。 – Revive