Skip to content

Instantly share code, notes, and snippets.

@cengkuru
Created June 13, 2016 05:07
Show Gist options
  • Save cengkuru/7c9e085245375ec14b2791a13842f860 to your computer and use it in GitHub Desktop.
Save cengkuru/7c9e085245375ec14b2791a13842f860 to your computer and use it in GitHub Desktop.
Dynamically change page title with angularJS
// It's very handy to add references to $state and $stateParams to the $rootScope
// so that you can access them from any scope within your applications.
// For example, <li ng-class="{ active: $state.includes('contacts.list') }">
// will set the <li> to active whenever 'contacts.list' or one of its
// decendents is active.
.run([ '$rootScope', '$state', '$stateParams',
function ($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
}])
//set up pageTitle by state
.state('home', {
url: '/home',
templateUrl : 'views/home.html',
data : { pageTitle: 'Home' }
})
//in the html
<title ng-bind="$state.current.data.pageTitle"></title>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment