I am unable to use jQuery with angular2. Where a friend of mine got it working (on mac) it is not on my windows machine.
The errors:
jquery-ui.js:1 Uncaught ReferenceError: require is not defined
angular2.dev.js:23935 EXCEPTION: TypeError: jQuery(...).find(...).sortable is not a function in [null]
angular2.dev.js:23925 EXCEPTION: TypeError: jQuery(...).find(...).sortable is not a function in [null]BrowserDomAdapter.logError @ angular2.dev.js:23925
angular2.dev.js:23925 ORIGINAL EXCEPTION: TypeError: jQuery(...).find(...).sortable is not a functionBrowserDomAdapter.logError @ angular2.dev.js:23925
angular2.dev.js:23925 ORIGINAL STACKTRACE:BrowserDomAdapter.logError @ angular2.dev.js:23925
angular2.dev.js:23925 TypeError: jQuery(...).find(...).sortable is not a function at EditPresentationComponent.ngOnInit
The piece of code where we use jquery.
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() {
var self = this;
// Initialize Sortable on lists
var oldList, newList, item, oldIndex;
jQuery(this.elementRef.nativeElement).find('.slide-categories .sortable-list').sortable({
start: function(event, ui) {
item = ui.item;
oldIndex = item.index();
newList = oldList = ui.item.parent().parent();
},
change: function(event, ui) {
if (ui.sender) newList = ui.placeholder.parent().parent();
// Check for empty list and hide/show instruction text
if (jQuery('.my-presentation-column .agile-list').has('li:not(".ui-sortable-helper")').length) {
self.isMyPresentationEmpty = false;
} else {
self.isMyPresentationEmpty = true;
}
},
stop: function(event, ui) {
if (oldList[0] != jQuery(event.toElement).parent().parent().parent().parent()[0]) {
if (jQuery(event.target).parent().hasClass('slide-categories')) {
if (oldIndex == 0) {
jQuery(event.target).prepend(item.clone());
} else {
jQuery(event.target).find('li:eq(' + (oldIndex - 1) + ')').after(item.clone());
}
} else {
item.remove();
}
}
},
connectWith: ".sortable-list"
}).disableSelection();
Overal when I execute npm install jquery or npm install jquery-ui I get
`[email protected] extraneous
as result, so it is installed.
I hope someone can help me with this.
declare var jQuery: any;does it work?