Solveduniversal starter How to set meta data in index.html
✔️Accepted Answer
@nicky-lenaers
My solution should work on server-side,
at leats it works for me, otherwise it makes no sense for SEO :)
https://github.com/matiishyn/vs-seo/blob/master/src/angular2-meta.ts#L68 - this should work
but as you can see it's the 'update', so maybe you need those tags already present in index.html (may be empty), like I have here: https://github.com/matiishyn/vs-seo/blob/master/src/index.html#L9
If you need to create an element you may take a look how I do it for canonical
- https://github.com/matiishyn/vs-seo/blob/master/src/angular2-meta.ts#L174
Other Answers:
Hello, I was looking for the solution too. Just build an angular5 project and wanted seo to work with angular-universal. I didn't find it here so I am adding it:
import { Component } from '@angular/core';
import { Title, Meta, MetaDefinition } from '@angular/platform-browser';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
public constructor(public meta: Meta, public pageTitle: Title) {
pageTitle.setTitle("MySite.COM");
const keywords: MetaDefinition = {
name: "keywords",
content: "angular2, java, javaEE, angular-universal"
}
const description: MetaDefinition = {
name: "description",
content: "This is a description"
}
this.meta.addTags([keywords, description]);
}
title = 'app';
}
So people can find this:
I wanted to change meta tags and page title in angular5 during the prerender phase. That led me to here. I finally just started searching the documentation and the solution was there clear as day. The solution lets you even change meta tags and page title dynamically in angular5. This is just for demonstration purposes. The code for meta tag update and page title update needs to be probably moved in the real application.
Here i have seen angular2-meta.ts
but how can i set meta data for pages?
Also can it update pages meta tags means can i see it when view the page source ?
Thanks in advance