2017-07-02 15 views

回答

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屬性)。