jQuery is not defined for angular 2
Wasted a good amount of time, here is what I did and didn't help.
npm uninstall -g angular-cli
npm uninstall -g @angular/cli
npm cache clear --force
npm cache clean
npm install -g @angular/cli
and all other usual things,
- clear browser cache
- restart browser
- kill and re-run ng serve
In my case I had to do the following:
npm install --save @types/jquery
Import jquery in the .angular-cli.json
"scripts": [
"../node_modules/jquery/dist/jquery.js"
],
change code from
import $ from 'jquery';
to
import * as jquery from 'jquery';
note: issue started after angular upgrade from 4.2 to 5.2
You need to import jquery with angular-cli
.
Edit your angular-cli.json
file.
Find script
array and add jquery.
"scripts": [
"../node_modules/jquery/dist/jquery.min.js"
],