1
我不敢說我的函數中的任何函數或變量不能稱之爲 - 這 - 裏面的YouTube API事件(onReady等)
我有onReady事件(YouTube的API事件)
還當我這樣做的console.log(本)的結果是功能
內不確定這是我的打字稿代碼
//這個類從離子2
我不敢說我的函數中的任何函數或變量不能稱之爲 - 這 - 裏面的YouTube API事件(onReady等)
我有onReady事件(YouTube的API事件)
還當我這樣做的console.log(本)的結果是功能
內不確定這是我的打字稿代碼
//這個類從離子2
您應該使用箭頭功能這樣的:
isOn :boolean = false;
createPlayer(): void {
return new window['YT'].Player(this.youtube.playerId, {
height: this.youtube.playerHeight,
width: this.youtube.playerWidth,
playerVars: {
rel: 0,
showinfo: 0
},
events: {
'onReady':() => { /* Put your logic here! */ }
'onStateChange':() => { this.isOn = true; /* Now it should work! */ }
}
});
}
當使用定時功能,this關鍵字引用本身的功能,但使用箭頭功能時,這個屬性不會被覆蓋並仍然引用組件實例(您在其中定義了navCtrl屬性)。