Angular 2与JQuery一起使用 [英] Angular 2 used with JQuery

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

问题描述

我正在尝试将jQuery与Angular 2 Cli一起使用.

I'm trying to use JQuery with Angular 2 Cli.

我通过使用npm install jquery --save并将import $ from 'jquery/dist/jquery'添加到app.module.ts安装了JQuery.

I installed JQuery by using npm install jquery --save and adding import $ from 'jquery/dist/jquery' to app.module.ts.

我在Chrome Cannot find module 'jquery/dist/jquery'.)中遇到此错误.但是我可以在node_modules中找到jquery文件夹.

I get this error in Chrome Cannot find module 'jquery/dist/jquery'.). But I can find the jquery folder in node_modules.

我使用JQuery是因为我想使用具有阴影效果的此标头在我的项目中.在不使用Material Design或其他UI组件的情况下,我找不到这种类型的标题的有角度的版本(因为我不希望使用它,因为它会更改项目中的某些样式).

I'm using JQuery because I want to use this header with shadow effect in my project. I can't find an angular version of this type of header without using Material Design or other UI components (as I prefer not to use this because it changes some of the styling in my project).

推荐答案

还有另一种非常简单的方法将jQuery添加到您的项目中.

There's another, very simple method to add jQuery into your project.

  • index.html代码中包含jQuery.

<script src="jquery.min.js"></script>

然后仅在指定组件内声明它:

Then just declare it inside specified component:

declare let $:any;

这篇关于Angular 2与JQuery一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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