简体   繁体   中英

How to import JQuery UI to angular 8 Project

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;

You should use it like (call a function):

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

PS: 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM