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

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -