[英]typescript problem with jquery type definition
I use Angular 9 universal, Typescript version ~3.7.5 and I installed both jQuery and its type definition using:我使用 Angular 9 Universal,Typescript 版本 ~3.7.5,我使用以下方法安装了 jQuery 及其类型定义:
npm i jquery npm i @types/jquery
Then I added jQuery in the types field in the tsconfig file.然后我在 tsconfig 文件的 types 字段中添加了 jQuery。 However after I run the app I still get this error:但是,在我运行该应用程序后,我仍然收到此错误:
Cannot find name '$'.找不到名称“$”。 Do you need to install type definitions for jQuery?你需要为 jQuery 安装类型定义吗? Try "npm i @types/jquery" and then add "jquery" to the types field in your tsconfig.`尝试“npm i @types/jquery”,然后将“jquery”添加到 tsconfig 中的类型字段。`
What is the problem here?这里有什么问题?
Install jQuery安装 jQuery
npm install --save jquery
Install jQuery Definition安装 jQuery 定义
npm install -D @types/jquery
than include jquery in a component like this比在这样的组件中包含 jquery
import * as $ from 'jquery';
Example:例子:
$(selector).hide();
OR或者
declare var jQuery: any;
Example:例子:
jQuery(selector).hide();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.