jQuery is not defined for angular 2

前端 未结 3 652
猫巷女王i
猫巷女王i 2020-12-15 10:08

I am trying to use ng2-datetime. However, when I follow the instruction and installed npm install --save ng2-datetime, I get the following error.

I have tri

3条回答
  •  醉酒成梦
    2020-12-15 10:42

    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

提交回复
热议问题