我在angular 6中使用ng2-Meta。我在index.html文件中设置了默认的meta标签。我想要实现的是,通过单击共享按钮,可以将我在标题和说明中设置的任何内容(应在元标记中更新)和值都共享给特定的共享介质。
这是我的index.html代码:
<meta property="og:title" content="web site name" />
<meta property="og:type" content="website" />
<meta property="og:url" content="site name" />
<meta property="og:image" content="site logo" />
<meta property="og:site_name" content="web site name" />
<meta property="fb:admins" content="19289---1301817" />
<meta property="og:description" id="description" content="Great mental health experience starts with MindCentral. Join us on a mission to better the world and ourselves." />
<meta name="description" id="description" content="Great mental health experience starts with MindCentral. Join us on a mission to better the world and ourselves." />
在功能上单击ts文件:
this.titleService.setTitle('web site name');
this.meta.updateTag({ name: 'description', content: 'I just received this '+ awardName +' Award on MindCentral! Join me to become better therapist.' })
this.meta.updateTag({ name: 'og:title', content: 'Mind Central' })
this.meta.updateTag({ name: 'og:description', content: 'I just received this '+ awardName +' Award on MindCentral! Join me to become better therapist.' })
this.meta.updateTag({ name: 'og:image', content: 'image url' })
它总是向我显示我在index.html文件中设置的说明,而不是我正在更新的说明。
我也清除了浏览器的历史记录。但是并没有受到影响。请帮帮我..
尝试使用metaService,如文档中所述:
import { Component, OnInit } from '@angular/core';
class ProductComponent implements OnInit {
...
constructor(private metaService: MetaService) {}
ngOnInit() {
this.metaService.setTitle('Product page for '+this.product.name);
this.metaService.setTag('og:image',this.product.imageURL);
}
}
在此处查看文档以进行正确的引导ng meta docs
您还可以通过stackblitz的代码提供更多信息,以便我们为您提供帮助。