簡體   English   中英

從onreadystatechange Angular 2調用另一個函數

[英]call another function from onreadystatechange Angular 2

我怎么可以叫我的組件功能之一來自onreadystatechange (因為它不承認this是我的課,但作為xmlhttpelement

xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
          this.anotherFunction(xmlhttp); //this is considered as xmlhttp instead of my class which contains this function
        }
    }

使用箭頭功能代替:

xmlhttp.onreadystatechange = () => {
...
}

這樣, this將參照組件實例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM