Reputation: 341
I'm working on a project where I want an event listener to be on the page when the page loads to wait for a message (a message from an external source will be sent instantly to this page when this page loads, so it has to be able to listen for it). Is there a way to do this in a TypeScript module? or does it have to be external of the module?
Possibly something like:
module MyModule {
export class MyClass{
constructor { ... }
public addEventListeners() : void { ... }
...
}
}
window.onload = () => {
var class: MyClass = new MyClass();
class.addEventListeners();
};
Upvotes: 1
Views: 117
Reputation: 1880
You should specify module name and use something else from class
which is reserved word:
window.onload = () => {
var classInstance = new MyModule.MyClass();
classInstance.addEventListeners();
};
Upvotes: 1