diff --git a/modules/core/client/directives/page-title.client.directive.js b/modules/core/client/directives/page-title.client.directive.js new file mode 100644 index 0000000000..bea8817a67 --- /dev/null +++ b/modules/core/client/directives/page-title.client.directive.js @@ -0,0 +1,32 @@ +(function () { + 'use strict'; + + angular.module('core') + .directive('pageTitle', pageTitle); + + pageTitle.$inject = ['$rootScope', '$interpolate', '$state']; + + function pageTitle($rootScope, $interpolate, $state) { + var directive = { + retrict: 'A', + link: link + }; + + return directive; + + function link(scope, element) { + $rootScope.$on('$stateChangeSuccess', listener); + + function listener(event, toState) { + var applicationCoreTitle = 'MEAN.js', + separeteBy = ' - '; + if (toState.data && toState.data.pageTitle) { + var stateTitle = $interpolate(toState.data.pageTitle)($state.$current.locals.globals); + element.html(applicationCoreTitle + separeteBy + stateTitle); + } else { + element.html(applicationCoreTitle); + } + } + } + } +})(); diff --git a/modules/core/client/directives/page-title.client.directives.js b/modules/core/client/directives/page-title.client.directives.js deleted file mode 100644 index b3c3f9f440..0000000000 --- a/modules/core/client/directives/page-title.client.directives.js +++ /dev/null @@ -1,40 +0,0 @@ -(function () { - 'use strict'; - - angular.module('core') - .directive('pageTitle', pageTitle); - - pageTitle.$inject = ['$rootScope', '$timeout', '$interpolate', '$state']; - - function pageTitle($rootScope, $timeout, $interpolate, $state) { - var directive = { - restrict: 'A', - link: link - }; - - return directive; - - function link(scope, element) { - $rootScope.$on('$stateChangeSuccess', listener); - - function listener(event, toState) { - var title = (getTitle($state.$current)); - $timeout(function () { - element.text(title); - }, 0, false); - } - - function getTitle(currentState) { - var applicationCoreTitle = 'MEAN.js'; - var workingState = currentState; - if (currentState.data) { - workingState = (typeof workingState.locals !== 'undefined') ? workingState.locals.globals : workingState; - var stateTitle = $interpolate(currentState.data.pageTitle)(workingState); - return applicationCoreTitle + ' - ' + stateTitle; - } else { - return applicationCoreTitle; - } - } - } - } -}());