繁体   English   中英

如何在 angular 7 上添加第三方插件 jquery?

[英]How to add third party plugin jquery on angular 7?

嗨,我一直在尝试在我的 App Angular 7 上添加第三方 jquery 插件。到目前为止,我已经完成了:在 angular.json 中添加了如下文件的位置:

"scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "src/assets/js/ticker/jquery.easy-ticker.min.js",
              "node_modules/bootstrap/dist/js/bootstrap.min.js"
 ]

在我的 AppComponent 中:

declare var $: any; interface JQuery { easyTicker(options?: any):
JQuery; }

尝试执行:

 ngAfterViewInit() {

    $('.ultimasExecucoes').easyTicker({
      visible: 1,
      interval: 4000
    });
}

在我的模板中

<div class="ultimasExecucoes">
            <ul>
            <li *ngFor="let workFlow of execucoesEncerradas"> 
                {{workFlow.nomeWorkFlow}} - Data Início: {{workFlow.dataInicioWf | date : 'dd/MM/yyyy HH:mm:ss'}} 
                - Data Encerramento: {{workFlow.dataEncerramentoWf | date : 'dd/MM/yyyy HH:mm:ss'}} 
                - Resultado: {{workFlow.resultadoExecucao}}
            </li>
            </ul>
        </div>

但是我的页面上没有任何反应。 如何添加插件 jquery ?

嗨,在我阅读了很多关于 jquery 类型的文章后,我解决了这个问题:

  1. 首先你需要安装 jquery/types: npm install --save @types/jquery
  2. 在目录nodes_modules/@types内我创建了一个文件夹“easyticker”(插件名称)
  3. 进入目录“easyticker”我创建了文件:index.d.ts里面我把这个:

声明模块“easyTicker”

接口 JQuery { easyTicker(options?: any): JQuery; }

  1. 在我的组件上,我导入了 jquery:

从 'jquery' 导入 * 作为 jQuery

  1. 然后我调用了我的插件:

ngAfterViewInit() {

 /* JqueryEasyTicker */ (<any>$)( document ).ready(function() { (<any>$)('#ultimasExecucoes').easyTicker({ visible: 1, interval: 8000 }); }); }

暂无
暂无

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

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