Allows to control the page title from the AngularJS route system, controllers or any other component through an injectable service.
ngPageTitle - Page title service (run tests)
To get started add the module to your app and configure the page title provider:
angular.module('app', ['ngPageTitle'])
.config(function($pageTitleProvider) {
// Use the current doc title
$pageTitleProvider.setDefaultTitle();
// Set a custom default title
$pageTitleProvider.setDefaultTitle('My App');
});
Then setup the $pageTitle
property along your routes:
$routeProvider.when('path/to', {
// ...
pageTitle: 'Route title'
});
The document title will automatically update every time the route changes with success.
It's also possible to change the routes within any component that supports
injection through the $pageTitle
service, with the set
method:
function MyAppCtrl($pageTitle) {
$pageTitle.set('Controller title');
}
ngPageTitleI18n - Page title service with internationalization support (run tests)
The iternationalization support is provided by the ng-i18next, and all titles will be parsed through the plugin before been set to the document, read the i18next documentation to understand all supported features.
To get started add the module to your app and configure the page title provider:
angular.module('app', ['ngPageTitleI18n'])
.config(function($pageTitleProvider) {
// Use the current doc title
$pageTitleProvider.setDefaultTitle();
// Set a custom default title
$pageTitleProvider.setDefaultTitle('default.title');
});
Then setup the $pageTitle
property along your routes:
$routeProvider.when('path/to', {
// ...
pageTitle: 'path.title'
});
The document title will automatically update every time the route changes with success.
It's also possible to change the routes within any component that supports
injection through the $pageTitle
service, with the set
/update
method:
function MyAppCtrl($pageTitle) {
$pageTitle.set('path.title');
}
The $pageTitle
must be a valid i18next string to allow correct localization,
as the following JSON:
{
"path": {
"title": "My path title",
"variableTitle": "__varName__ path title"
}
}
There's also the possibility to interpolate variables through the service,
we can set the value of varName
giving set
an variables object as the
second parameter.
function MyAppCtrl($pageTitle) {
$pageTitle.set('path.variableTitle', {varName: 'Variable'});
// => Variable path title
}
Or just update
the current title, if already been set within the route.
This is specially usefull when you have to resolve a promise before set the
title.
Notice that for the update
method only the variables object is required.
$routeProvider.when('path/to', {
// ...
pageTitle: 'path.title',
resolve: {
data: function($http, $pageTitle) {
// Updates the page title after promise resolved
return $http.get('/content/1.json')
.success(function(data) {
$pageTitle.update({varName: data.title});
});
}
}
});
The route will be update only when the route is changed with success, so we won't show non replaced title.