我正在构建通过官方JS SDK使用Deezer播放器的网络应用。我遇到的问题是我无法从Deezer事件订阅中访问我的Angular组件。箭头函数不了解的上下文this,因此我无法调用组件的方法并将值传递给它们。什么是实现这一目标的正确方法?app.component.ts// ...declare var DZ;// ...export class AppComponent implements OnInit { currentTrack: any = null; constructor() {} ngOnInit(): void { DZ.init({ appId : '8', channelUrl : 'https://developers.deezer.com/examples/channel.php', player : { onload : this.onPlayerLoaded } }); } onPlayerLoaded() { DZ.player.playAlbum(302127); DZ.Event.subscribe('player_position', console.log); DZ.Event.subscribe('current_track', (response) => { // I would like to pass response.track to setCurrentTrack() there }); } setCurrentTrack(track) { this.currentTrack = track; }}index.html// ...<head> <script type="text/javascript" src="https://e-cdns-files.dzcdn.net/js/min/dz.js"></script></head>// ...
添加回答
举报
0/150
提交
取消