I want to retrieve the .state('name')
when switching locations in angular.
Within my run()
, I can access the $state
object:
.run(function($rootScope, Analytics, $location, $stateParams, $state) {
console.log($state);
However, attempting to access$state.current
yields an empty object
.run(function($rootScope, $location, $stateParams, $state) {
console.log($state.current);
Example configuration:
.config(function($stateProvider, $urlRouterProvider, AnalyticsProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('home', {
url: '/',
views: {
'': {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
},
'navigation@home': {
templateUrl: 'views/partials/navigation.html',
controller: 'NavigationCtrl'
},
'weekly@home': {
templateUrl: 'views/partials/weekly.html',
controller: 'WeeklyCtrl'
},
'sidepanel@home': {
templateUrl: 'views/partials/side-panel.html',
controller: 'SidePanelCtrl'
},
'shoppanel@home': {
templateUrl: 'views/partials/shop-panel.html',
controller: 'ShopPanelCtrl'
},
'footer@home': {
templateUrl: 'views/partials/footer.html',
controller: 'FooterCtrl'
}
}
})