For some reason $state.current is always blank when I try to access it from a directive controller. Does the directive load before state evaluation? If so, is there a work around for this? I need to show the correct navigation based on the state in a SPA
For example in my view, I have: <navigation></navigation>
My directive:
angular.module('app')
.directive('navigation', function($state){
return {
restrict: 'E',
controller: function() {
alert($state.current.name);
}
}
});
My routes:
angular.module('app') .config(function ($stateProvider, $urlRouterProvider, $locationProvider) { $urlRouterProvider.otherwise('/home'); $stateProvider .state('home', { url: '/home', views: { "title": { template: "<title>Home</title>" }, "body": { templateUrl: 'app/components/home/homeView.html', }, "navigation" : { templateUrl: 'app/shared/navigation/homeNavBarView.html' } } }) });
The way i have it set up is that i create the module separately, then i setup routing in a separate file, and the directive is also in a separate file. Then they are loaded in an index file in order. Not sure if this has anything to do with it
What am I doing wrong?