【问题标题】:how to access global variable inside onerror event of audio object如何访问音频对象的onerror事件中的全局变量
【发布时间】:2017-10-08 13:58:16
【问题描述】:

我想从 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;
        }
    }

【问题讨论】:

    标签: angular audio onerror


    【解决方案1】:

    删除function 关键字并使用箭头函数符号()=>

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

    【讨论】:

      猜你喜欢
      • 2016-07-02
      • 2019-08-19
      • 1970-01-01
      • 2016-05-04
      • 1970-01-01
      • 1970-01-01
      • 2016-05-09
      • 2016-10-06
      • 1970-01-01
      相关资源
      最近更新 更多