【发布时间】:2019-07-23 00:07:10
【问题描述】:
我正在使用 @ng-toolkit/universal 在 firebase 上创建一个服务器端渲染应用程序。
何时可以使用以下方法直接在 ngOnInit 中成功添加或更新 og-tags: 从'@angular/platform-browser'导入{ Meta };
当我在 ngOnInit 中更新 og-tags 时,一切正常;当我订阅路由器事件时。
但是当我想用 firebase 数据库值更新这些 og 标记时遇到问题。我的代码是这样的:
ngOnInit(){
/* This part works:
1- I see 'the first step' string in the server console.
2- The og:type update works and og-tag debuger can find it.
*/
console.log('The first step');
this.meta.updateTag({ property: 'og:type', content: 'og:type.for.test' });
firebase.database().ref('test/ssr').on('value', function (snapshot) {
/* This part dose not work:
1- I can't see 'the first step' string in the server console.
But I can find this string in client side console.
2- og-tag debuger can not find 'og:title'. But I can find it updated in my browser.
*/
console.log('The Secound Step. No Working');
this.meta.updateTag({ property: 'og:title', content: 'og:title.for.test' });
});
}
我在firebase上部署应用程序,没有问题,代码运行良好,但似乎代码的第二部分服务于客户端而不是服务器端。
有什么问题?我该如何解决?
【问题讨论】:
标签: angular firebase facebook-opengraph server-side-rendering universal