在Angular 5中使用jquery插件 [英] Using jquery plugin with Angular 5

查看:76
本文介绍了在Angular 5中使用jquery插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Angular 5项目中使用以下datepicker,但不确定如何导入它:-

I'm using trying to use the following datepicker in my Angular 5 project but I'm not sure how to import it:-

https://bootstrap-datepicker.readthedocs.io/en/Latest/index.html#

我正在使用Angular CLI构建项目,并且已将bootstrap-datepicker.min.js文件添加到我的angular-cli.json文件的脚本部分中:-

I'm using Angular CLI to build my project and I've added the bootstrap-datepicker.min.js file into my scripts section in my angular-cli.json file:-

  "scripts": [
    "../node_modules/jquery/dist/jquery.js",
    "../node_modules/popper.js/dist/umd/popper.js",
    "../node_modules/bootstrap/dist/js/bootstrap.js",
    "../js/custom.js",
    "../js/bootstrap-datepicker.min.js"
  ]

我还将JQuery导入了我的Angular组件:-

And I've also imported JQuery into my Angular component:-

import * as $ from 'jquery';

..它的工作原理是,我可以在组件中引用$对象,并获得处理JQuery函数的句柄.但是,当我执行以下操作时:-

..which does work as I can reference the $ object in my component and get a handle to a load of JQuery functions. However, when I do something like:-

$("dateField").datepicker()

它告诉我该功能在JQuery对象上不可用.有谁知道如何在Angular中使用它?

It tells me the function is not available on the JQuery object. Does anyone have any ideas how to use this in Angular?

谢谢

亚当

推荐答案

代替

import * as $ from 'jquery';

尝试

declare let $: any;

另一方面,如果您绝对不需要jQuery,请不要使用它.有很多可用的角度日历,并且ng-bootstrap是一个本地的角度库,提供了bootstrap组件,而不是bootstrap.js

On a side note, don't use jQuery if you don't absolutely need it. There are plenty of angular calendar available, and ng-bootstrap is a native angular library providing bootstrap components, instead of bootstrap.js

这篇关于在Angular 5中使用jquery插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆