如何在整个Angular应用程序中引用Youtube Iframe API播放器

时间:2020-12-31 18:57:10

I've been digging around the Stack Overflow threads, and can't seem to find this issue addressed exactly. I set up and Angular app, and I would like to be able to call methods on a YouTube API from within multiple controllers and directives (such as playVideo() and pauseVideo() etc)

我一直在挖掘Stack Overflow线程,似乎无法准确地解决这个问题。我设置了Angular应用程序,我希望能够在多个控制器和指令(例如playVideo()和pauseVideo()等)中调用YouTube API上的方法。

The video will be persistent throughout the site.

该视频将在整个网站中保持不变。

I initially set up the API via a service and subsequently injected it into the various controllers. I used a $rootscope.$broadcast to send a message when the player was ready, but I could never get the actual player returned, just an empty object.

我最初通过服务设置API,然后将其注入各种控制器。我使用$ rootscope。$ broadcast在播放器准备就绪时发送消息,但我永远无法让实际播放器返回,只是一个空对象。

To make matters worse, I rebuilt the site statically so have no example code to show here, but was hoping someone might be able to outline the basic procedure here.

更糟糕的是,我静态重建了网站,所以没有示例代码在这里显示,但希望有人可以在这里概述基本程序。

Thanks, James

1 个解决方案

#1


2  

YouTube Topic explorer uses iframe inside the angular script. You can basically create your own function or directive to use the iFrame.

YouTube主题资源管理器在角度脚本中使用iframe。您基本上可以创建自己的函数或指令来使用iFrame。

#1


2  

YouTube Topic explorer uses iframe inside the angular script. You can basically create your own function or directive to use the iFrame.

YouTube主题资源管理器在角度脚本中使用iframe。您基本上可以创建自己的函数或指令来使用iFrame。