加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在angular4中导入jquery

发布时间:2020-12-17 07:48:51 所属栏目:安全 来源:网络整理
导读:为了在angualr4项目中导入jquery,我执行以下操作: npm install --save jquerynpm install --save-dev @types/jquery 在app.component.ts中 import $from 'jquery';or import * as $from 'jquery'; 当运行“ng serve”时 我有这些错误 ERROR in C:/jquery-an
为了在angualr4项目中导入jquery,我执行以下操作:
npm install --save jquery
npm install --save-dev @types/jquery

在app.component.ts中

import $from 'jquery';
or 
import * as $from 'jquery';

当运行“ng serve”时
我有这些错误

ERROR in C:/jquery-angular/jqueryintegration/node_modules/@types/jquery/index.d.ts (47,40): ',' expected.

ERROR in C:/jquery-angular/jqueryintegration/node_modules/@types/jquery/index.d.ts (2370,' expected.
.....
.....
.....
ERROR in C:/jquery-angular/jqueryintegration/node_modules/@types/jquery/index.d.ts (4311,85): ';' expected.

ERROR in C:/jquery-angular/jqueryintegration/node_modules/@types/jquery/index.d.ts (4311,92): Expression expected.

ERROR in C:/jquery-angular/jqueryintegration/node_modules/@types/jquery/index.d.ts (4455,1): Declaration or statement expected.

ERROR in C:/jquery-angular/jqueryintegration/node_modules/@types/jquery/index.d.ts (30,45): Generic type 'JQueryStatic<TElement,HTMLElement>' requires 2 type argument(s).
.....
.....
.....
ERROR in C:/jquery-angular/jqueryintegration/node_modules/@types/jquery/index.d.ts (4475,33): Generic type 'PlainObject<T,any>' requires 2 type argument(s).

ERROR in C:/jquery-angular/jqueryintegration/src/app/app.component.ts (2,8): Module ''jquery'' has no default export.

ERROR in C:/jquery-angular/jqueryintegration/src/app/app.component.ts (2,8): Module ''jquery'' has no default export.
webpack: Failed to compile.

我的环境细节:

>tsc --version
Version 2.3.2

>ng --version
@angular/cli: 1.0.3
node: 6.10.2
os: win32 x64

其他家属:

"dependencies": {
    "@angular/common": "^4.0.0","@angular/compiler": "^4.0.0","@angular/core": "^4.0.0","@angular/forms": "^4.0.0","@angular/http": "^4.0.0","@angular/platform-browser": "^4.0.0","@angular/platform-browser-dynamic": "^4.0.0","@angular/router": "^4.0.0","core-js": "^2.4.1","jquery": "^3.2.1","rxjs": "^5.1.0","zone.js": "^0.8.4"
  },"devDependencies": {
    "@angular/cli": "1.0.3","@angular/compiler-cli": "^4.0.0","@types/jasmine": "2.5.38","@types/jquery": "^3.2.3","@types/node": "~6.0.60","codelyzer": "~2.0.0","jasmine-core": "~2.5.2","jasmine-spec-reporter": "~3.2.0","karma": "~1.4.1","karma-chrome-launcher": "~2.1.1","karma-cli": "~1.0.1","karma-coverage-istanbul-reporter": "^0.2.0","karma-jasmine": "~1.1.0","karma-jasmine-html-reporter": "^0.2.2","protractor": "~5.1.0","ts-node": "~2.0.0","tslint": "~4.5.0","typescript": "~2.2.0"
  }

“导入”加载默认的javascript文件还是必须以某种方式配置?

尝试这个

从’jquery / dist / jquery.min.js’导入*为$;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读