[英]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.