I have a component. Inside I have the following:
constructor() {
this.something = "Hello";
}
document.addEventListener('click', doSomething());
function doSomething(e) {
console.log(this.something) // this is undefined
}
I want to make it so that I can access this.something inside of the doSomething(e). Usually I would just create a variable outside and use var self = this; then reference self.something to get to that "Hello". Unfortunately in angular 2, I am getting errors with self not being defined, etc. How can I access this.something inside of the event listener I created?
doSomethingdefined? Please, provide the context for the code you're posting. The snippet above will throw syntax error. Becauseconstructoris outside of a class.