I would like to change the isMyPresentationEmpty variable when the stop event of JQuery sortable fires. Unfortunately the 'this' variable is undefined in that scope... Do you know how I am able to access the variable from that scope?
Thank you so much in advance!
import { Component, OnInit, ElementRef, Inject } from 'angular2/core';
declare var jQuery: any;
@Component({
selector: 'edit-presentation',
templateUrl: 'app/Edit Presentation/edit_presentation.component.html'
})
export class EditPresentationComponent implements OnInit {
elementRef: ElementRef;
isMyPresentationEmpty = true;
constructor(@Inject(ElementRef) elementRef: ElementRef) {
this.elementRef = elementRef;
}
ngOnInit() {
// Initialize Sortable on lists
var oldList, newList, item;
jQuery(this.elementRef.nativeElement).find('.sortable-list').sortable({
start: function(event, ui) {
item = ui.item;
newList = oldList = ui.item.parent().parent();
},
change: function(event, ui) {
if (ui.sender) newList = ui.placeholder.parent().parent();
},
stop: function(event, ui) {
// Check for empty list and hide/show instruction text
if (jQuery(event.target).has('li').length) {
this.isMyPresentationEmpty = false;
} else {
this.isMyPresentationEmpty = true;
}
},
connectWith: ".sortable-list"
}).disableSelection();
}
}