Add dynamic metadata to an Angular CLI Project

Share this video with your friends

Send Tweet

In this lesson we will create a UiService and inside that service we create some application defaults, import the Title and Meta services from @angular/platform-browser and create a function called setMetaData.

This function will set the metadata of the application based on the config parameter.

We set some defaults and define a list with tags. We then loop over the tags and invoke the updateTags method from the Meta service.

Once our service is ready we update the ProductListComponent and ProductDetailComponent to dynamically set the meta data by using the tap operator in the pipe from our Subscription.

After building and deploying the app we see that the meta data gets updated, and we can now share the app over Social Media and get rich social previews.

Billy Long
Billy Long
~ 6 years ago

I was able to verify the tags on the product list and detail page. I pushed my site to now and tried the twitter validator but it failed: INFO: Page fetched successfully INFO: 3 metatags were found ERROR: No card found (Card error)

Any ideas?

Emiliano Potignano
Emiliano Potignano
~ 6 years ago

Same here, any ideas why?