Skip to content

Instantly share code, notes, and snippets.

@ketsugi
Last active February 3, 2017 00:02
Show Gist options
  • Select an option

  • Save ketsugi/9942600baf3a5338bb3f607828ee7f39 to your computer and use it in GitHub Desktop.

Select an option

Save ketsugi/9942600baf3a5338bb3f607828ee7f39 to your computer and use it in GitHub Desktop.
Setting page title with angular-ui-router
const app = angular.module('app', ['ui.router'])
// Set up some states
.config(($stateProvider) =>
{
$stateProvider.state('login',
{
data: { pageTitle: 'Login' },
templateUrl: 'login.partial.html',
url: 'login',
});
})
// Set the page title
.run(($rootScope, $transitions) =>
{
const baseTitle = 'Site Name';
$rootScope.pageTitle = baseTitle;
$transitions.onSuccess({}, ($transition$) =>
{
$rootScope.pageTitle = ($transition$.to().data && $transition$.to().data.pageTitle) ? `${baseTitle} - ${$transition$.to().data.pageTitle}` : baseTitle;
});
});
<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
<title ng-bind="pageTitle"></title>
</head>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment