i started using typescript angularjs. have written simple class responsible drag , drop behavior (or in future). right in handledragend function when access canvas element error
cannot read property of undefined
below code - if tell me doing wrong grateful.
class toolbox { private canvas; constructor(canvas) { this.canvas = canvas; $(".beacon").draggable({ helper: 'clone', cursor: 'pointer', start: this.handledragstart, stop: this.handledragend }); } handledragstart() { console.log('drag started!'); } handledragend() { var pointer = this.canvas.getpointer(event.e); console.log('drag end!'); return; } }
since class methods defined on toolbox.prototype, value of this getting lost when pass in methods directly.
change:
start: this.handledragstart, stop: this.handledragend to:
start: () => this.handledragstart(), stop: () => this.handledragend() that preserve value of this calling methods on instance.
Comments
Post a Comment