Last active
February 3, 2017 00:02
-
-
Save ketsugi/9942600baf3a5338bb3f607828ee7f39 to your computer and use it in GitHub Desktop.
Setting page title with angular-ui-router
This file contains hidden or 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
| 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; | |
| }); | |
| }); |
This file contains hidden or 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
| <!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