如何在音频对象的onerror事件中访问全局变量

时间:2017-10-08 13:58:16

标签: angular audio onerror

我想从audio.onerror函数访问isDisabled变量,并希望重置isDisabled的值,但无法设置它。

public isDisabled: boolean = false;
private verifyPrompt(url: string): boolean{
           let audio = new Audio(this.promptMessageUrl);
           this.isDisabled = 
           audio.load;
        audio.onerror = function(e){
            this.isDisabled = true;
        }
    }

1 个答案:

答案 0 :(得分:0)

删除function关键字并使用箭头函数表示法()=>

audio.onerror = (e) => {
    this.isDisabled = true;
}