Reputation: 29
I am planning to change meta Title,Meta keywords and Meta description dynamically using AngularJS 1.x to reflect in Facebook,Twitter,Google Plus and LinkedIn.
Is there any way to change dynamically? I am using REST Api calls.
Thanks, -Venkat
Upvotes: 3
Views: 1097
Reputation: 174
I would recommend you to use this library which is suggested by Tristan also. It works perfectly fine. and compatible with dynamic expressions also.
For updating meta-tags you can simply use the following markup in your view(s):
<update-title title="A new title"></update-title>
<update-meta charset="ISO-8859-1"></update-meta>
<update-meta http-equiv="Content-Language" content="es"></update-meta>
<update-meta name="description" content="A page specific description"></update-meta>
<update-meta property="og:title" content="Minions"></update-meta>
<update-meta itemprop="description" content="A page specific itemprop description"></update-meta>
You can simply install it using this command:
bower install angular-update-meta
Hope it will help someone.
Upvotes: 1
Reputation: 7072
I also ran into this problem so I've created a library just for this. You can view it over here.
You can use it in two ways:
For each state you've defined using ui-router you can attach the following custom data: simpleSeoTitle
, simpleSeoDescription
, simpleSeoKeywords
. These 3, whenever the state is active, will change the page's title, description, or keywords.
It also exposes a service called simpleSeoService
. This service has 3 properties, title,
description, and
keywords`. These 3 are defined as getter and setter. These are useful when you have dynamic properties you want to attach.
Upvotes: 0
Reputation: 3321
You can use ng-bind
to dynamically create the content of any tag.
For example:
<title ng-bind="pageTitle()"></title>
And then in your controller:
$scope.pageTitle = function () {
return 'the page title you want to add dynamically';
};
Google now renders javascript so the dynamic page title, and meta tags, will be indexed correctly.
Upvotes: 0
Reputation: 3350
Use Angular-update-meta , it will help you to update meta tags dynamically.
https://github.com/jvandemo/angular-update-meta
Upvotes: 0