在下面的打印腳本函數中,'this'沒有解析爲EmailValidator的實例。我怎樣才能糾正這個函數,使其解析爲正確的EmailVaildator實例,並反過來讓我可以訪問_registerServices?訪問'this'Inside Promise
class EmailValidator {
constructor(private _registerServices: RegisterServices) { }
isAvailable(c: AbstractControl): Promise<ValidationResult> {
let q = new Promise((resolve, reject) => {
this._registerServices.emailIsAvailable(antiForgeryToken(), c.value)
.then(result => {
// Need to actually check the result.
resolve({ "emailtaken": true })
},
error => {
// Need to communicate the server error? Probably not.
resolve({ "servererror": true })
});
});
return q;
}
}
嗯。它看起來像胖箭頭應該已經這樣做了。並看看生成的JavaScript,它似乎別名'this'正確。你確定這是你所看到的問題嗎? – Thilo
@Thilo我發現問題有點隱藏,問題在別處。我發現瞭如何糾正我的問題,但是有關'爲什麼'發生了問題的詳細信息,我真的很感謝一些指導。我會發布我的解決方案。 –