简体   繁体   English

我如何使用@types/jqueryui 和 angular2(打字稿)

[英]How do i use @types/jqueryui along with angular2 (typescript)

I would like to use jqueryui in my angular application我想在我的角度应用程序中使用 jqueryui

I can import jquery like this我可以像这样导入 jquery

import * as $ from 'jquery';

But how do i import '@types/jqueryui' from https://www.npmjs.com/package/@types/jqueryui但是我如何从https://www.npmjs.com/package/@types/jqueryui导入 '@types/jqueryui'

Since jqueryui is an interface, i am not able to import it由于 jqueryui 是一个接口,我无法导入它

How i am using jquery我如何使用 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
    }
}

Work Around: (Not the solution through @types/jqueryui )解决方法:(不通过@类型的解决方案/ jQueryUI的

You can use @types/jqueryui for typing/autocomplete support.您可以使用@types/jqueryui进行打字/自动完成支持。

Root HTML:根 HTML:

Import jquery and jquery UI js files导入 jquery 和 jquery UI js 文件

<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.注意:欢迎通过@types/jqueryui (正确方式)提供任何本机支持。 please let me know if you find any solution.如果您找到任何解决方案,请告诉我。

Add on top of your *.ts file reference to d.ts types file在 *.ts 文件引用之上添加对d.ts类型文件的引用

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

It did the trick for me.它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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