最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论