Angular 2.x change the <head> in the head (outside my application)

I think this should be easy, but I cannot find how to do it.

I have something like

 <html> <head> <title>{{'a' + 'b'}}</title> </head> <body> <my-app>Loading...</my-app> </body> </html> 

It seems like I can't access anything outside my-app .

In angular 1.x it was easy, I was able to add ng-app for any element ( <html ng-app="myApp"> ).

Now I think that I can only bootstrap in the body.

I know that I can somehow manually boot (I have not tried it yet), but dynamically changing the title in single-page applications should be super-easy, right?

+7
source share
1 answer

Angular2 cannot be loaded into the whole html. But you can use the header service .

A service that can be used to get and set the title of the current HTML document.

It has 2 methods:

 getTitle() setTitle() 

Be sure to check the dependency attachment to see how you can use the services.

EDIT:

Starting with version (2.0.0), you can do this:

 import { Title } from '@angular/platform-browser'; export class SomeComponent { constructor(title: Title) { // title.getTitle(); // title.setTitle('new title'); } } 

And the documents for the Title service are now here: https://angular.io/docs/ts/latest/api/platform-browser/index/Title-class.html

+8
source

All Articles