I have a typescript class myClass with an array instance:
module myModule {
export class myClass {
arrayElements: Array<string>;
...
}
}
and in this class I have a function myfunction()
where I create a button and I handle click event:
function myfunction(){
...
var button = (<HTMLButtonElement>document.createElement("BUTTON"));
button.onclick = function () {
// something
}
...
}
in "something" I'd like to update my array instance (i.e. push a string), but I don't know how. If I try
this.arrayElements.push("example");
When I click on button (in .html page) I have this error :
Uncaught TypeError: Cannot read property 'push' of undefined
most likely because "this" is instance of HTMLButtonElement.
If I try with
myClass.prototype.arrayElements.push("example");
I have the same error. Is there a way to realize my purpose?