Created
June 13, 2016 05:07
-
-
Save cengkuru/7c9e085245375ec14b2791a13842f860 to your computer and use it in GitHub Desktop.
Dynamically change page title with angularJS
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
// 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