简体   繁体   English

Angular 2 - 如何使关键字和描述的index.html文件标题和元标记动态化

[英]Angular 2 - how do I make my index.html files title and meta tags for keywords and description dynamic

Angular 2 - how do I make my index.html files title and meta tags for keywords and description dynamic. Angular 2 - 如何使关键字和描述的index.html文件标题和元标记动态化。

I'm using typescript with angular 2. 我正在使用带有角度2的打字稿。

Example of my tags: 我的标签示例:

<!DOCTYPE html>
<html lang="en" prefix="og: http://ogp.me/ns#" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>title needs to be dynamic</title>
    <base href="/"></base>

    <meta charset="UTF-8">
    <meta name="fragment" content="!"/>
    <meta name="description" content="description needs to be dynamic"/>
    <meta name="keywords" content="keywords needs to be dynamic" />

This is my route: 这是我的路线:

{ path: '/', component: Home, as: 'Home', data:{title: 'Welcome Home'}},

I've tried this but it didnt work: 我试过这个,但它没有用:

 <title>{{title}}</title>

There is a Title service. 标题服务。 Otherwise you're currently on your own. 否则你现在独自一人。 You can use pure JS functionality querySelector()... 您可以使用纯JS功能querySelector()...
There are plans to support more tags in the <head> . 有计划在<head>支持更多标签。
I'm not too deep into SEO but I think it would be better to use a server side solution for meta tags. 我对SEO没有太深入,但我认为使用服务器端解决方案更好。 I doubt search engines pick up meta tags that are added after the initial page load. 我怀疑搜索引擎会选择在初始页面加载后添加的元标记。

Plunker (doesn't update the window title because the app runs in an iframe but using the browsers inspect tool shows it in the <head><title>....</title></head> ) Plunker (不更新窗口标题,因为应用程序在iframe中运行但使用浏览器检查工具在<head><title>....</title></head>

There's also the @ngx-meta/core plugin, which might help you to make page titles and meta tags dynamically (on the route config and class constructor level). 还有@ ngx-meta / core插件,可以帮助您动态制作页面标题和元标记(在路由配置和类构造函数级别)。

Please refer the repository for instructions. 请参阅存储库以获取说明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对于Angular2项目,我如何连接从typescript生成的所有JavaScript文件并将它们添加到我的index.html文件中 - For Angular2 project, In gulp how do I concat all my JavaScript files that were generated from typescript and add them to my index.html file 如何链接回index.html上的选项卡? - How do I link back to a tab on my index.html? 如何使 Vue 从 assets 文件夹中导入文件,而不是 index.html 内的硬编码脚本标签 - How to make Vue import files from assets folder instead of hardcoded script tags inside of index.html 如何获得对我的HTML元标记之一的引用? - How do I get a reference to one of my HTML meta tags? 动态将meta标签添加到index.html以共享链接预览 - Dynamically add meta tags to index.html for shared link previews 如何在AngularJs 1.x中动态更改元标题,元关键字,元描述? - how to change Meta Title,Meta Keywords,Meta Description dynamically in AngularJs 1.x? 如何将contact.handlebars添加为index.html而不是contact.html的链接? - How do I add contact.handlebars as a link to my index.html instead of contact.html? 我如何在没有Index.html或.php的情况下将WebApplication文件运行到服务器? - How can I run my WebApplication files to the server without an Index.html or.php? 如何使用 JavaScript 在我的 index.html 文件中嵌入 API 调用? - How do I embed an API call in my index.html file using JavaScript? 如何从Workbox实际显示更新的index.html? - How do I actually display my updated index.html from Workbox?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM