DEV Community

Cover image for Updating OG meta tag issue in angular
saajan-pixel
saajan-pixel

Posted on

Updating OG meta tag issue in angular

Updating OG meta tags issue

<!-- Open Graph meta tags for Facebook -->
<meta
property="og:url"
content="https://demo.ndplhrm.com/"

<meta
property="og:type"
content="website"

<meta
property="og:title"
content="Your App Title"

<meta
property="og:description"
content="Description of your app"

<meta
property="og:image"
content="https://images.unsplash.com/photo-1682686581221-c126206d12f0?q=80&w=1770&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"

This is OG meta tag declared in index.html file of Angular. In one of component i need to update this meta tags. I have used Meta Service provided by @angular/platform-browser to update meta tags but the tags doesnot get updated.

Note: SSR is not implemented

In the attached image, on clicking facebook icon i have updated the meta tags.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (2)

Collapse
 
geromegrignon profile image
Gérôme Grignon

The Meta service runs JavaScript to update the meta tags but browser won't executed JavaScript while indexing your page.
That's why you need SSR or SSG to generate the proper meta tags before the browser loads the page.

Collapse
 
saajanpixel profile image
saajan-pixel

Thank you for your response.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay