javascript - How to import JQuery UI to angular 8 Project - Stack Overflow

I'm working on angular app in which i want to implement draggable. There were questions about that

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 ponent 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;

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 ponent 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;

Share Improve this question edited Jan 13, 2020 at 16:43 isherwood 61.2k16 gold badges122 silver badges170 bronze badges asked Jan 13, 2020 at 16:34 Jan KozubJan Kozub 592 silver badges6 bronze badges 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. – isherwood Commented Jan 13, 2020 at 16:44
Add a ment  | 

1 Answer 1

Reset to default 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745362007a4624402.html

相关推荐

  • javascript - How to import JQuery UI to angular 8 Project - Stack Overflow

    I'm working on angular app in which i want to implement draggable. There were questions about that

    4小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信