我想使用 API 调用在元标记中设置动态信息。当我通过检查检查时,它会显示更新的数据,但是当我在 Facebook 上分享链接时,它不会反射(reflect)更新的数据。
索引.html
<meta name="description" content="Create and share your biography">
<meta name="og:url" content="window.location.href">
<meta name="og:title" content="TEACHERLIFE -SPANISH LESSONS">
<meta name="og:description" content="So I’m in my classroo...">
在 component.ts 中:
import { Meta, Title } from '@angular/platform-browser';
constructor(private metaService: MetaService,
private meta: Meta,) {}
ngOnInit() {
this.meta.updateTag( {name: 'og:description', content:"testdescription"});
}
最佳答案
Facebook Share 不解析 javascript,因此它只拦截 index.html 页面上的静态元数据。
请参阅 github 社区中的完整讨论。
https://github.com/jvandemo/angular-update-meta/issues/13
关于 Angular 6 : Dynamic Meta tag is not working when sharing page on facebook using og:description tag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54689982/