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;