1

I'm working on angular app in which i want to implement draggable. There were questions about that in the past but nothing works for me. What I tried:

npm install jquery jquery-ui

and then adding following lines to angular.json

"scripts": [
  "../node_modules/jquery/dist/jquery.min.js",
  "../node_modules/jquery-ui/jquery-ui.js"
]

and then importing it to my component like

declare let $: any; 

or

import $ from 'jquery';

or

import $ from 'jquery';
import 'jqueryui';

but I'm still getting error:

TSLint: unused expression, expected an assignment or function call(no-unused-expression)

when placing this line in ngOnInit:

$('#draggable' as any).draggable;

1
  • 2
    As Artyom Krasnyuk said, jQuery isn't a great choice here. You have other options that are better suited to an Angular application. Commented Jan 13, 2020 at 16:44

1 Answer 1

3

You should use it like (call a function):

$( "#draggable" ).draggable();

P.S: Don't use jQuery with Angular :) Consider using drag-and-drop from Angular CDK (developed by Angular team): https://material.angular.io/cdk/drag-drop/overview

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I didn't know about Angualr material drag and drop. Works perfectly for me :). Thanks yall
doesn't work for me, the cdk is laking the functionalities I need, for exemple select multiple list items with mouse jqueryui.com/selectable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.