Blog
Skip to end of metadata
Go to start of metadata

Angular 2 provides a Title service that you can use to set the title of a page. This is good, of course, for SEO. Here's how to use it.

import { Component } from '@angular/core';
import { Title } from '@angular/platform-browser'; 

@Component({
	selector: 'my-app',  
	viewProviders: [Title],  
	template: `<h1>MyApp</h1>` 
}) 
export class MyAppComponent {
	constructor(title: Title) {
		title.setTitle('My App - Page Title');
	}
}

The service automatically creates the title element in the head if needed and also sets the value.  The service also has a getter method to get the title.

Related Resources

Blog Posts