I have a service written with TypeScript. Something like:
export default class AServiceClass {
constructor(private $http: ng.IHttpService, ...) {}
method1(data : any) : void {
this.$http(...)
}
method2(data : any) : void {
this.$http(...)
}
}
And I have a controller class, that utilize this service:
export default class AControllerClass {
constructor(private aService: AServiceClass, ...) {}
$onInit(){
let method = true ? this.aService.method1 : this.aService.method2;
method({ ... data ... });
}
}
Service methods throw an Exception - this is undefind
. If I use it like this.aService.method1({ ... data ... })
, all is fine. Ofc I can do method.bind(aService)({ ... data ... })
or method.call(aService, { ... data ... })
, but why there is a scope difference?
Thx.