This should be (using Function.prototype.bind ):
return this.http.post(url + 'login', body, options)
.map(this.handleData.bind(this))
.catch(this.handleError.bind(this));
Or (using arrow functions ):
return this.http.post(url + 'login', body, options)
.map((res) => this.handleData(res))
.catch((error) => this.handleError(error));
, , , this, , , this , .
this, -.
:
export class Authenticate {
...
private handleData = (res: Response) => {
...
}
private handleError = (error: any) => {
...
}
}
, "" , , , .
:
class A {
method1() { }
method2 = () => {}
}
:
var A = (function () {
function A() {
this.method2 = function () { };
}
A.prototype.method1 = function () { };
return A;
}());
class A {
constructor() {
this.method2 = () => { };
}
method1() { }
}
- method2 () , .