如何在AngularJs 1.x中动态更改Meta Title,Meta Keywords,Meta Descripti

how to change Meta Title,Meta Keywords,Meta Description dynamically in AngularJs 1.x?

本文关键字:Meta Descripti Title Keywords 动态 AngularJs      更新时间:2023-09-26

我计划使用AngularJS 1动态更改元标题,元关键字和元描述。在Facebook,Twitter,Google Plus和LinkedIn上反映。

是否有办法动态更改?我正在使用REST Api调用。

谢谢,venkat

我建议你使用Tristan也建议的这个库。它工作得很好。并且与动态表达式也兼容。

要更新元标签,您可以在视图中简单地使用以下标记:

<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>

您可以简单地使用以下命令安装它:

bower install angular-update-meta

希望对大家有所帮助。

使用Angular-update-meta,它将帮助你动态更新meta标签。

https://github.com/jvandemo/angular-update-meta

您可以使用ng-bind动态创建任何标记的内容。

例如:

<title ng-bind="pageTitle()"></title>

然后在控制器中:

$scope.pageTitle = function () {
    return 'the page title you want to add dynamically';
};

Google现在呈现javascript,因此动态页面标题和元标签将被正确索引。

我也遇到了这个问题,所以我为此创建了一个库。你可以在这里看。

有两种用法:

  1. 对于使用ui-router定义的每个状态,您可以附加以下自定义数据:simpleSeoTitle, simpleSeoDescription, simpleSeoKeywords

  2. 当状态处于活动状态时,这3项将改变页面的标题、描述或关键词。
  3. 它还公开了一个名为simpleSeoService的服务。该服务有3个属性,title,描述, and关键字。这三个定义为getter和setter。