我正在構建通過官方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>// ...
如何從第三方庫訪問角度分量
慕絲7291255
2021-05-17 20:18:30