javascript - Angular 2: How do you access component variables within an event (scope issue) -


i have click event on component, needs access private variables component itself. seem running scoping issue: keyword this no longer refers component's scope rather scope of event. help!

onclick(event){   for(var = 0; < this.arr.length; i++) { ... } } 

in above example, this.arr undefined because not belong event scope.

how access component scope here?

add .bind(this) fix this

element.addeventlistener("click", this.onclick.bind(this), false); 

Comments

Popular posts from this blog

cron - how to properly run Python script with crontab on every system startup -

elasticsearch - Is the order of operations guaranteed in a bulk update? -

Slow performance first queries on SQL Azure -