import ngModule from '../module'; /** * Watch for a state transition to change the page title * * @return {Object} The directive */ directive.$inject = ['$transitions', '$translate', '$state']; export default function directive($transitions, $translate, $state) { return { restrict: 'A', link: function($scope, $element, $attrs) { $transitions.onSuccess({}, transition => { let currentState = transition.targetState(); let currentRoute = currentState._definition.self; let parentRoute = currentState._definition.path[1].self; let moduleName; moduleName = $translate.instant(parentRoute.description); moduleName = moduleName ? `${moduleName} :` : ''; if (currentRoute == parentRoute) moduleName = ''; let pageName = $translate.instant(currentRoute.description); let paramId = $state.params.id ? `${$state.params.id} -` : ''; let title = `${moduleName} ${paramId} ${pageName}`; $element.html(title); }); } }; } ngModule.directive('vnTitle', directive);