app run rootScope state stateParams function rootScope state statePara

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
app.run(['$rootScope', '$state', '$stateParams', function ($rootScope, $state, $stateParams) {
// It's very handy to add references to $state and $stateParams to the $rootScope
// so that you can access them from any scope within your applications.For example,
// <li ng-class="{ active: $state.includes('profile') }"> will set the <li>
// to active whenever 'profile' or one of its descendants is active.
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
// http://stackoverflow.com/questions/27120308/angular-ui-router-urlrouterprovider-when-not-working-when-i-click-a-ui-sref
var stateRedirectMap = {
'profile': 'profile.feed',
'companies': 'companies.business'
};
$rootScope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams){
if (toState.name in stateRedirectMap) {
event.preventDefault();
$state.go(stateRedirectMap[toState.name]);
}
})
}]);