
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
angular-update-meta
Advanced tools
Dynamically update meta tags and document title for SEO purposes in your AngularJS application.
Dynamically update meta tags and document title for SEO purposes in your AngularJS application.
View example plunk right here.
First install the module using bower:
$ bower install angular-update-meta
then add the updateMeta
module to the dependencies of your AngularJS application module:
angular.module('yourApp', ['updateMeta']);
Suppose you have the following markup in your template:
<html>
<head>
<title>Website title</title>
<meta charset="utf-8" />
<meta http-equiv="Content-Language" content="en" />
<meta name="description" content="Application wide description" />
<meta property="og:title" content="The Rock" />
<meta itemprop="description" content="Application wide description for Schema.org (Google+ uses this)">
<script type="application/ld+json"></script>
</head>
<body ng-app="yourApp">
...
</body>
</html>
Now you can 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>
<update-script content="structuredData" type="application/ld+json"></update-script>
And if you want to use Google Structured Data, create an object like this in $scope:
$scope.structuredData = {
"@context": "http://schema.org",
"@type": "Organization",
"url": "http://www.example.com",
"name": "Unlimited Ball Bearings Corp.",
"contactPoint": {
"@type": "ContactPoint",
"telephone": "+1-401-555-1212",
"contactType": "Customer service"
}
};
So the head is updated to:
<html>
<head>
<title>A new title</title>
<meta charset="ISO-8859-1" />
<meta http-equiv="Content-Language" content="es" />
<meta name="description" content="A page specific description" />
<meta property="og:title" content="Minions" />
<meta itemprop="description" content="A page specific itemprop description">
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"url": "http://www.example.com",
"name": "Unlimited Ball Bearings Corp.",
"contactPoint": {
"@type": "ContactPoint",
"telephone": "+1-401-555-1212",
"contactType": "Customer service"
}
}
</script>
</head>
<body ng-app="yourApp">
...
</body>
</html>
Only existing meta elements are updated.
If the meta element does not exist yet, it is NOT added, so make sure they exist in your original head
element.
Whenever an update-meta
element is processed, the original meta
in the head is updated with the new value.
This allows you to dynamically set the meta
element values with values from within your markup and child states.
You can also update link tags. If you have the following markup in your layout:
<html>
<head>
<link rel="stylesheet" href="http://example.com" />
<link rel="alternate" href="http://example.com/another" hreflang="" />
<link rel="alternate" href="http://example.com/another" id="test" />
</head>
</html>
and you have the following markup in your view:
<update-link rel="stylesheet" href="http://example.com/updated"></update-link>
<update-link rel="alternate" href="http://example.com/another" hreflang="es"></update-link>
<update-link rel="alternate" href="http://example.com/another-updated" id="test"></update-link>
then the head will be updated to:
<html>
<head>
<link rel="stylesheet" href="http://example.com/updated" />
<link rel="alternate" href="http://example.com/another" hreflang="es" />
<link rel="alternate" href="http://example.com/another-updated" id="test" />
</head>
</html>
A rel
and a href
attribute must be supplied to the directive. The directive will try querying the DOM using the rel
and href
attributes, and optionally an id
. Any of the supported attributes (id
, charset
, crossorigin
, hreflang
, integrity
, media
, methods
, referrerpolicy
, sizes
, target
, title
, type
) will be updated.
Dynamic AngularJS expressions are supported too:
<update-meta property="og:title" content="{{ title }}"></update-meta>
In the example above, the og:title
is automatically updated whenever title
changes.
Prerender.io will grab the updated values and store them in your page snapshots so they are optimized for SEO purposes.
This allows you to conveniently update the meta
elements for each individual page in your AngularJS single page application and store them correctly in your Prerender page snapshots.
You can preview the prerender output by using the _escaped_fragment_=
parameter as described in the prerender.io documentation.
To update the build in the dist
directory:
$ gulp
To run the unit tests (for both concatenated and minified version):
$ gulp test
http-equiv
property
elements to support the Open Graph protocolelement.querySelector()
method to fix #4FAQs
Dynamically update meta tags and document title for SEO purposes in your AngularJS application.
We found that angular-update-meta demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.