ng-bind used for the title tag inside the header behaves weird. This is my code:
<title page-title ng-bind="page_title"></title>
and here's the output:
My Page Sucks
<title page-title="" ng-bind="page_title" class="ng-binding"></title>
it goes outside instead of inside the title tag
here's a snippet of the pageTitle directive:
streamViewApp
// page title
.directive('pageTitle', [
'$rootScope',
'$timeout',
function($rootScope, $timeout) {
return {
restrict: 'A',
link: function() {
var listener = function(event, toState) {
var name = ($rootScope.site_settings) ? (($rootScope.site_settings[0] != undefined) ? $rootScope.site_settings[0] : 'StreamView' ): 'StreamView';
var default_title = name.value;
$timeout(function() {
$rootScope.page_title = (toState.data && toState.data.pageTitle)
? default_title + ' - ' + toState.data.pageTitle : default_title;
});
};
$rootScope.$on('$stateChangeSuccess', listener);
}
}
}
]);
UPDATE:
Works well when called within the body tag, weird thing happens when called in head
<body><title page-title="" ng-bind="page_title" class="ng-binding">My Page Sucks</title>
Instead of using
ng-binddefine the pagetitle as custom data with router state.Then in directive you can get hold of
toStateobject and set the next page title from there.