Should probably add something like this to the app I'm working on...
This is a somewhat hackish way to do it:
function MyCtrl($window) {
$window.document.title = 'Hello Title';
}
MyCtrl.$inject = ['$window'];
I think the magic at docs.angularjs.org is watching $location.hashPath
and then look up the page title in a data structure. For this approach
to work I guess you would need access to all the page titles in the
root-scope.
From http://docs.angularjs.org/docs-combined.js:
this.$watch('$location.hashPath', function(hashPath) {
if (hashPath.match(/^!/)) {
var parts = hashPath.substring(1).split('/');
self.sectionId = parts[1];
self.partialId = parts[2] || 'index';
self.pages = angular.Array.filter(NG_PAGES, {section:self.sectionId});
self.partialTitle = (angular.Array.filter(self.pages,
function(doc){return doc.id == self.partialId;})[0]||{}).name ||
'Error: Page Not Found!';
}
});
Another approach may be to add a $route.onChange(fn) and update the title there?
I would love to hear the angular devs take on this!
Cheers!
/Mårten
2011/6/13 Dan <hae...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "angular" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to angular+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/angular?hl=en.
>
>
something like this (writing directly in e-mail, so please verify)
angular.service('pageTitleSetter', function($window) {
return function(documentTitle) {
$window.document.title = documentTitle;
};
}, {$inject:'$window'});
And now, in any controller you can use it:
function MyCtrl(pageTitleSetter) {
pageTitleSetter('my page title');
}
MyCtrl.$inject = ['pageTitleSetter'];
Now your controller does require a 'kitchen sink' to setup a title, it
is readable and there is no need to make volatile assumptions when
writing tests.
What do you think?
Regards,
Witold Szczerba
--
You received this message because you are subscribed to the Google Groups "angular" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/5mwaEwAm-QUJ.
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/xG-zIC-xBXE/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
Nicolas
Nicolas
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/xG-zIC-xBXE/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to angular+unsubscribe@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/xG-zIC-xBXE/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to angular+unsubscribe@googlegroups.com.