我正在尝试使用TwitchAPI在我的web应用程序中嵌入频道。
说明如下:
<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
正确使用脚本的障碍是什么?