I use AngularJS with Typescript and the definitions from DefinitelyTyped.
I define my services and configs like this:
module MyModule {
export module Services {
export class MyService {
constructor() {
console.log(this); // this refers to service instance, as expected
}
}
}
}
module MyModule {
export module Configurations {
export class MyConfiguration {
constructor() {
console.log(this); // this refers to Window!?
}
}
}
}
And register them like this:
var app = angular.module('MyApp', ...);
app.config(MyModule.Configurations.MyConfiguration);
app.service('MyService', MyModule.Services.UserService);
This works just fine but I noticed that this is resolved differently: when the service is instantiated the console logs [object Object] as expected, referencing the instance of the service. But when the config is processed, the console logs [object Window], the global window object.
Why?