limitless.directive('pageHeader', ['config','$state',function (config,$state) { return { restrict: 'E', templateUrl: config.baseUrl + 'app/components/pageHeader.html', scope: { user:'=' }, controller: function ($scope) { $scope.hasPrev = false; $scope.breadcrumbs = []; $scope.title =''; $scope.current = ''; $scope.currentIcon = ''; function update(toState, hasPrev) { var b = []; if (toState.data === undefined) { return; } toState.data.breadcrumbs = toState.data.breadcrumbs || []; for (var i = 0; i < toState.data.breadcrumbs.length; i++) { var s = toState.data.breadcrumbs[i].split('#'); var state = s[0]; if (state!==undefined && state!==null && state==='NOBREADCRUMBS'){ break; } var icon = s.length > 1 ? s[1] : ''; b.push({ state: state, icon: icon }); } $scope.hasPrev = hasPrev; $scope.breadcrumbs = b; $scope.title = toState.data.title; $scope.current = toState.name; $scope.currentIcon = toState.data.icon; } update($state.current, false); $scope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) { update($state.current, fromState!==null && fromState!==undefined && !fromState.abstract); }); } } }]);