javascript - Angular 2 - how do I make my index.html files title and meta tags for keywords and description dynamic - Stack Over

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.

I'm using typescript with angular 2.

Example of my tags:

<!DOCTYPE html>
<html lang="en" prefix="og: " xml:lang="en" xmlns="">
  <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: '/', ponent: Home, as: 'Home', data:{title: 'Wele Home'}},

I've tried this but it didnt work:

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

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

I'm using typescript with angular 2.

Example of my tags:

<!DOCTYPE html>
<html lang="en" prefix="og: http://ogp.me/ns#" xml:lang="en" xmlns="http://www.w3/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: '/', ponent: Home, as: 'Home', data:{title: 'Wele Home'}},

I've tried this but it didnt work:

 <title>{{title}}</title>
Share Improve this question edited Apr 16, 2016 at 16:07 AngularM asked Apr 16, 2016 at 16:02 AngularMAngularM 16.6k29 gold badges103 silver badges175 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

There is a Title service. Otherwise you're currently on your own. You can use pure JS functionality querySelector()...
There are plans to support more tags in the <head>.
I'm not too deep into SEO but I think it would be better to use a server side solution for meta tags. 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>)

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

Please refer the repository for instructions.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744689213a4588107.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信