Skip to content

Instantly share code, notes, and snippets.

@MehulATL
Created June 29, 2015 23:18
Show Gist options
  • Save MehulATL/e5b7d7d849c34a1250cd to your computer and use it in GitHub Desktop.
Save MehulATL/e5b7d7d849c34a1250cd to your computer and use it in GitHub Desktop.
declare view title in ui.router state declaration
.run(function($rootScope, $injector, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
$rootScope.$title = function() {
if (angular.isFunction($state.current.title)) {
return $injector.invoke($state.current.title, $rootScope, {
$scope: $rootScope,
$currentState: $state.current
});
} else if (angular.isString($state.current.title)) {
return $state.current.title;
} else {
return 'Hello World';
}
};
})
// ng-bind the <title> to $title()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment