【发布时间】:2018-09-12 10:02:33
【问题描述】:
我的元标签可以在 Facebook 和 Twitter 上使用,但不知何故我破坏了它们。我查看了示例,但看不到问题所在。 (没有错误。)标签只是不会更改 index.html 中的默认值。我正在使用 Angular Universal 5。
与我找到的示例不同,我没有在构造函数中编写标签。不确定这是否是一个因素。我一定错过了使用 Meta 服务的一些规则。这是代码...
import { Meta } from '@angular/platform-browser';
...
constructor( ... private metaService: Meta ... ) {}
ngOnInit () {
...
// <!-- Facebook meta data -->
this.metaService.addTags([
{property: 'og:title', content: 'test' },
{property: 'og:url', content: 'url' },
]);
// <!-- Twitter meta data -->
this.metaService.addTag({name: 'twitter:title', content: 'test });
...
}
【问题讨论】:
-
它不需要在构造函数中。如果您尝试使用 updateTag 而不是 addTag 会怎样?
-
@大卫谢谢! updateTag 有效。我在颤抖……我一定是通过更改 index.html 中的默认(静态)标签来破坏它。