Set or Update new Title and Meta Tag- Angular

Anil Verma
1 min readJan 13, 2022

--

add/update title and meta tags at runtime on Pages

Problem- In Angular applications, we usually see the same title and meta tag along with all pages. So problem is, can we update or set different titles and meta tags in the angular applications?

The answer is Yes. But How?
This article is all about setting/updating different titles and meta tags along with all pages.

Title

To set different “Title” on the page(head section)

Step 1-

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

Step 2-

public constructor(private titleService: Title) { }ngOnInit() {
this.titleService.setTitle("your page title");
}

Same steps you can repeat on different pages where you want to set new Title of Page

Meta

To set/update different “Meta” on the page(head section)

Step 1-

import { Meta} from '@angular/platform-browser';

Step 2-

public constructor(private metaService: Meta) { }

Add New Meta Tags

ngOnInit() {
this.metaService.addTags([
{name: 'keywords', content: 'your keywords content'},
{name: 'description', content: 'your page description content'},
]);
}

Update Meta Tag

ngOnInit() {
this.metaService.updateTag({ name: 'keywords', content: 'your updated keywords content'});
}

Remove Meta Tag

ngOnInit() {
this.metaService.removeTag({ name: 'keywords', content: 'your updated keywords content'});
}

Happy Learning….👏👏👏👏

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Anil Verma
Anil Verma

Written by Anil Verma

Hi there 👋, I am Anil Verma, a full stack web developer, and JavaScript enthusiast. 👥 Ask me anything about web development. web- https://anilvermaspeaks.in/

Responses (2)

Write a response