How to use jQuery UI with Angular 2

前端 未结 5 2193
旧巷少年郎
旧巷少年郎 2020-12-06 01:18

Because I want to incorporate Drag and Drop functionality in my app, I decided to import jQuery UI to my Angular 2 project.

First I started by importing jQuery itse

5条回答
  •  醉梦人生
    2020-12-06 01:57

    npm install jquery jquery-ui --save

    npm install @types/jquery --save-dev

    import * as $ from 'jquery';
    import 'jquery-ui/ui/widgets/selectable.js';
    

    usage:

    ngAfterViewInit(): void {
        ($('.selectable') as any).selectable({..});
    }
    

    you may also want to import the stylesheet on style.scss if using sass

    @import '../node_modules/jquery-ui/themes/base/selectable.css';
    

    or

    in .angular-cli.json

    "styles": [
          "../node_modules/jquery-ui/themes/base/selectable.css",
          "./styles.scss"
    ],
    

提交回复
热议问题