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
Post a Comment