I am using Angular-CLI (webpack version) for my Angular 2 project and I also need to use jQuery (sadly. In my case, it's a dependency of Semantic-UI and I am using it for handling menu dropdowns).
The way I am using it:
npm install jquery --save
Then listing in it angular-cli.json
file in the scripts
array:
scripts": [
"../node_modules/jquery/dist/jquery.min.js"
]
So it gets included into bundle file and this file is automatically used to root html file:
<script type="text/javascript" src="scripts.bundle.js">
Then declare var $: any;
in files where I need it and it works well.
However there is a problem with ng test
tests, as Karma throws an error $ is not defined
.