I have developed a website using Angular 6 in the frontend. By default Angular is not SEO friendly, so in order to do that, I implemented it in the way of Angular-Universal or Angular SSR (Server Side Rendering). I updated the code and comparing the page sources from before and now, I can see my application inside the tags <app-root>
and </app-root>
, before only "loading..." would come.
I am using the MetaService
and TitleService
from @angular/platform-browser
to update the desired <meta>
tags for Facebook and Twitter and the <title>
tag respectively.
The problem is when I run the node server in my local system, view-source shows me the rendered meta
tags, but when I run the same code in node server on AWS VM, I don't get the rendered meta
tags, but other application code is available.
UPDATE:
The function that adds the meta
tags
updateMetaTags(egElement: Elements[]) {
this.url = 'https://example.com/eg/' + this.id;
const title = egElement[1].innerHTML;
this.tweetText = 'Check the latest blog on \"' + title + '\"';
this.meta.addTags([
{ property: 'og:url', content: this.url },
{ property: 'og:type', content: 'website' },
{ property: 'og:title', content: title },
{ property: 'og:description', content: 'Author: ' + egElement[2].innerHTML },
{ property: 'og:image', content: this.egElement[3].img }
]);
}
I call this function in ngOnInit(). It does the rendering properly in my local machine, but does not do it on the server.
egElement
and id
is returned from the service call to backend and meta
service has been imported and injected in the constructor.
meta
tags in both local and server, so the code is working. But it doesn't get rendered in view-source in server env. Please check the URL. Check the console, have added logs for calling the methodupdateMetaTags
. – Olgaolguin