Angular Universal不会从WebService调用中添加/更新Facebook共享预览图像/标题/描述的元标记

问题描述 投票:2回答:1

基本上,我是在Angular 8中创建一个新闻应用程序。新闻内容将添加到管理门户中,并在服务器中进行更新。在网站视图上,我们进行API调用以从服务器获取新闻数据。一切正常,我只想在FB,Twitter,Whatsapp等社交媒体网站上分享这些新闻。

因此我实现了[https://murhafsousli.github.io/ngx-sharebuttons/#/),但我的坏处是!:(它没有更新(图像,网址,描述,标题)的Facebook OG标签。在谷歌搜索之后,我知道这只能通过使从服务器端使用Angular Universal(https://medium.com/@maciejtreder/angular-server-side-rendering-with-ng-toolkit-universal-c08479ca688)通过节点js express服务器渲染角度应用程序。

然后我认为这将解决所有问题,,!问题仍然存在。进行网络服务调用后,它不会更改/更新元标记。只有meta标记中提供的静态内容才由动态内容更新,而不是动态内容。单击每条新闻时,我应该提供新的Title,Description和Image URL,但无效。

我用Google搜索来寻找自己是否面临类似情况。但是我可以看到很多,并且所有人都在寻找相同的东西,但是却找不到任何明确的答案或任何可行的解决方案。我编写此查询以找到任何人都可以给出可靠的答案,无论它是否有任何可能的解决方案或任何解决方法,或者这首先可以实现]

--------在Construcor中

      [
      {name: 'description', content: 'Title and Meta tags examples'},      
      {httpEquiv: 'Content-Type', content: 'text/html'},
      {property: 'og:title', content: "My Text"},
      {property: 'og:type', content: "TEst"},
      {property: 'og:image', content:"TEst"},
      {property: 'og:url', content: "TEst"},
      {property: 'og:description', content: "description"},
      {property: 'twitter:card', content: "description"}

   ]



---------IN ngOnInit     

 this.homeService.GetNews(id).subscribe(
      (result: any) => {
        if (result) {
          this.newsDetails = result;
          if(this.newsDetails.length > 0) {

            this.meta.updateTag({property: 'og:title', content: this.newsDetails[0].HeadLine});
            this.meta.updateTag({property: 'og:description', content: this.newsDetails[0].HeadLine });
            this.meta.updateTag({property: 'og:url', content:  this.ShareUrl });
            this.meta.updateTag({property: 'og:image', content: 'http://admin.xyz.com/CategoryFiles/'+this.newsDetails[0].ImageThumb});
            this.meta.updateTag({property: 'twitter:card', content: this.newsDetails[0].HeadLine });
          }

        }
      })

基本上,我是在Angular 8中创建一个新闻应用程序。新闻内容将添加到管理门户中,并在服务器中进行更新。在网站视图上,我们进行API调用以从服务器获取新闻数据。 ...

angular facebook-opengraph meta-tags angular-universal server-side-rendering
1个回答
0
投票

嘿,您对此有何解决方案?如果是,请告诉我。甚至我也在很多方面尝试它,但我没有理解。

© www.soinside.com 2019 - 2024. All rights reserved.