I have implemented the following code snippets:
isValidLogin():Observable<boolean> {
return this.http.get(this._checkLoginUrl)
.map(res=>res.json())
.map((res) => {
if (res.success) {
this.loggedIn = true;
}
return res;
});
}
Transpiled JavaScript:
LoginService.prototype.isValidLogin = function () {
var _this = this;
return this.http.get(this._checkLoginUrl)
.map(function (res) { return res.json(); })
.map(function (res) {
if (res.success) {
_this.loggedIn = true;
}
return res;
});
};
In the code snippet, loggedIn
is a public property of the class. However, it displays as undefined
, and this
here refers to the Map object context, making it unable to assign a value to loggedIn
.
I believe that the lambda expression should be able to access the context of the class object. Have I made any mistakes in my implementation?