6

I would like to use jqueryui in my angular application

I can import jquery like this

import * as $ from 'jquery';

But how do i import '@types/jqueryui' from https://www.npmjs.com/package/@types/jqueryui

Since jqueryui is an interface, i am not able to import it

How i am using jquery

 export class JqueryUIIntegrationComponent implements AfterViewInit{
        @ViewChild('jqueryElement') el:ElementRef;
        constructor() {
        }

    ngAfterViewInit() {
        console.log(this);
        $(this.el.nativeElement).slideUp(4000).slideDown(5000); // jquery function
        $(this.el.nativeElement).draggable(); //Since jqueryui is not imported this will not work
    }
}

2 Answers 2

1

Work Around: (Not the solution through @types/jqueryui )

You can use @types/jqueryui for typing/autocomplete support.

Root HTML:

Import jquery and jquery UI js files

<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>

Component:

In your component declare

declare var $:any;

use it in class like this

export class JqueryUIIntegrationComponent implements AfterViewInit {
    @ViewChild('jqueryElement') el:ElementRef;
    constructor() {
    }

    ngAfterViewInit() {
        console.log(this);
        $(this.el.nativeElement).draggable(); //same old style
    }
}

Note: Any native support through @types/jqueryui (right way) is welcomed. please let me know if you find any solution.

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

6 Comments

getting error on draggable() function. Any update on this!?
.draggable() is not a function. Do you have any plunker for this?
I am working in a live project, sorry didn't create a pluker. can you create a plunker with your usecase. so i can try to fix it? Looking at the error message looks like you did not import Jquery UI Make sure you have done this in your index.html <script src="code.jquery.com/jquery-2.2.4.min.js"></script> <script src="code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
-1 for suggesting declare var $:any; instead of npm install @types/jquery, or one of a dozen others ways to acquire the most widely used and disbursed type declaration ever. If I got -1 again for suggesting using an AMD library as a global, I would.
Please feel free to share if you have a working example jquery + jqueryUI through AMD
|
0

Add on top of your *.ts file reference to d.ts types file

///<reference path="../node_modules/@types/jqueryui/index.d.ts"/>

It did the trick for me.

Comments

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.