This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (title): Dynamic Title: Improve SEO
- Loading branch information
Showing
7 changed files
with
132 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
modules/core/client/directives/page-title.client.directives.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
angular.module('core') | ||
.directive('pageTitle', pageTitle); | ||
|
||
pageTitle.$inject = ['$rootScope', '$timeout', '$interpolate', '$state']; | ||
|
||
function pageTitle($rootScope, $timeout, $interpolate, $state) { | ||
var directive = { | ||
retrict: '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; | ||
} | ||
} | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49f6a83
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change requires you to add a pageTitle to each ui router route when porting existing modules.
49f6a83
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in directive page-title,
should be
?
49f6a83
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I will test that tonight. Would make the property optional as was intended in the first place.