简体   繁体   English

Angular 4 + ng2-datetime jQuery问题

[英]Angular 4 + ng2-datetime jQuery issue

Does anybody have luck using ng2-datetime package with ng4? 有人将ng2-datetime包与ng4结合使用会遇到运气吗? I am running into a jQuery issue as follows: 我遇到了一个jQuery问题,如下所示:

ERROR in /Users/markoffden/Sites/ato-card-front/node_modules/ng2-datetime/src/ng2-datetime/ng2-datetime.ts (175,27): Cannot find name 'jQuery'.
/Users/markoffden/Sites/ato-card-front/node_modules/ng2-datetime/src/ng2-datetime/ng2-datetime.ts (176,37): Cannot find name '$'.
/Users/markoffden/Sites/ato-card-front/node_modules/ng2-datetime/src/ng2-datetime/ng2-datetime.ts (192,19): Cannot find name '$'.
/Users/markoffden/Sites/ato-card-front/node_modules/ng2-datetime/src/ng2-datetime/ng2-datetime.ts (196,27): Cannot find name 'jQuery'.
/Users/markoffden/Sites/ato-card-front/node_modules/ng2-datetime/src/ng2-datetime/ng2-datetime.ts (197,37): Cannot find name '$'.
/Users/markoffden/Sites/ato-card-front/node_modules/ng2-datetime/src/ng2-datetime/ng2-datetime.ts (224,19): Cannot find name '$'.

Though I have followed all the accepted fixes for this around the web, such as: 尽管我已经在网络上关注了所有可接受的修复程序,例如:

npm install --save @types/jquery

and including: 并包括:

"types": ["jquery"]

in my tsconfig.json , but still get this error. 在我的tsconfig.json ,但仍然出现此错误。

I am using CLI. 我正在使用CLI。

UPD And my angular-cli.json is UPD而我的angular-cli.json

///...

"styles": [
    "../bower_components/bootstrap/dist/css/bootstrap.min.css",
    "../bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css",
    "../bower_components/font-awesome/css/font-awesome.min.css",
    "sass/styles.scss"
],
"scripts": [
    "../bower_components/jquery/dist/jquery.min.js",
    "../bower_components/bootstrap/dist/js/bootstrap.min.js",
    "../bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js",
    "../bower_components/bootstrap-timepicker/js/bootstrap-timepicker.js"
]

///...

I think that ngx-datepiker is the best option for now. 我认为ngx-datepiker是目前的最佳选择。 Switched to this lib. 切换到此库。

I had the same issue. 我遇到过同样的问题。 The only solution I was able to find is below. 我能够找到的唯一解决方案如下。

step 1: Install jQuery and types 步骤1:安装jQuery和类型

npm install jquery --save

npm install @types/jquery --save-dev

step 2: Add the library to the scripts in .angular-cli.json 步骤2:将库添加到.angular-cli.json中的脚本中

"scripts": [ "../bower_components/jquery/dist/jquery.min.js" ]

step 3: Add: /// <reference path="../node_modules/@types/jquery/index.d.ts" /> to the top of the src/typeings.d.ts file. 步骤3:src / typeings.d.ts文件顶部添加 /// <reference path="../node_modules/@types/jquery/index.d.ts" />

I tried using angular's approach for adding 3rd party libs first with no luck. 我尝试使用angular的方法先添加第3方库 ,但没有运气。

if you use angular-cli, add in typings.d.ts this: 如果您使用angular-cli,请在types.d.ts中添加以下内容:

declare var $: any;

declare var jQuery: any;

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

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