【发布时间】:2019-03-28 08:35:54
【问题描述】:
我正在尝试使用 Twitch API 在我的网络应用中嵌入频道。
说明如下:
<html>
<body>
<!-- Add a placeholder for the Twitch embed -->
<div id="twitch-embed"></div>
<!-- Load the Twitch embed script -->
<script src="https://embed.twitch.tv/embed/v1.js"></script>
<!-- Create a Twitch.Embed object that will render within the "twitch-embed" root element. -->
<script type="text/javascript">
new Twitch.Embed("twitch-embed", {
width: 854,
height: 480,
channel: "monstercat"
});
</script>
</body>
</html>
我已将https://embed.twitch.tv/embed/v1.js 文件包含在我的assets 文件夹和angular.json 中。
"scripts": [
"src/assets/twitch/twitch-embed-v1.js"
]
我的组件文件如下所示:
import Twitch from '../../../../../assets/twitch/twitch-embed-v1';
export class TwitchPlayerComponent implements OnInit {
ngOnInit() {
const options = {
width: 854,
height: 480,
channel: '424976424',
};
const player = new Twitch.Embed('twitch-embed', options);
player.setVolume(0.5);
}
}
该脚本出现在 Chrome devtools 的我的源面板中,但产生了以下错误:
Embed is not a constructor
正确使用脚本的障碍是什么?
【问题讨论】:
标签: angular typescript twitch