简体   繁体   English

不渲染instagram,twitter和其他嵌入角

[英]Does not render instagram, twitter and other embedded in angular

I am trying to show content from instagram, twitter and other libraries that allow embedding in sites. 我正在尝试显示来自instagram,twitter和其他允许嵌入网站的库中的内容。 The problem that I have is that it only renders the embedded content the first time and then when I go back to the same content the embed is not rendered again. 我遇到的问题是,它仅在第一次呈现嵌入的内容,然后当我返回相同的内容时,不会再次呈现嵌入。 :( :(

This is an example of what happens to me: https://stackblitz.com/edit/angular-vcv94j (I add the library js in index.html) 这是发生在我身上的一个示例: https : //stackblitz.com/edit/angular-vcv94j (我在index.html中添加了库js)

I am located in test-1 the embedded content renders and when I go to test-2 the embedded content does not render 我位于test-1中,嵌入内容将呈现,而当我进行test-2时,嵌入内容将不呈现

What solution could be given to this problem...? 该问题可以采取什么解决方案...? :S :S

Is there any way to trigger the events of the javascript libraries again? 有什么办法可以再次触发javascript库的事件吗?

If you're loading content dynamically (AJAX, for example), these embed services usually have a JavaScript API method that you need to call after inserting the contents into the page in order to render the posts. 如果您正在动态加载内容(例如AJAX),则这些嵌入服务通常具有JavaScript API方法,在将内容插入页面后,您需要调用该方法以呈现帖子。

Instagram, for example, have the window.instgrm.Embeds.process() , Facebook have FB.XFBML.parse(); 例如,Instagram具有window.instgrm.Embeds.process() ,Facebook具有FB.XFBML.parse(); .

You will find something similar for Twitter and other social media embeds. 您会在Twitter和其他社交媒体嵌入中找到类似的内容。

You are including Instagram's embed.js which searches for certain elements in the DOM and replaces them by iframe elements which embed the post. 您将包括Instagram的embed.js ,后者可在DOM中搜索某些元素并将其替换为嵌入帖子的iframe元素。

The script offers a global variable called instgrm which allows access to 该脚本提供了一个称为instgrm的全局变量,该变量允许访问

instgrm.Embeds.process()

which repeats that search. 重复该搜索。 You may call this each time your component has rendered. 您可以在每次渲染组件时调用它。

I have forked your example and modified it accordingly, following two different approaches: 我用两种不同的方法对您的示例进行了分叉并进行了相应的修改:

  1. Calling a service from the components 从组件调用服务
  2. Using a directive for elements with a data-instgrm-permalink attribute 对具有data-instgrm-permalink属性的元素使用指令

<script async src="//www.instagram.com/embed.js"></script>替换为<script async src="https://www.instagram.com/embed.js"></script>并将此行代码移至index.html头部

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM