1

I have an Angular 13 project where we use jquery. We use jquery because we are importing another project that is coded using jquery.

So, I ran npm install jquery, and got this in my package.json file: "jquery": "^3.5.1".

I checked the node_modules folder as well, and found that jquery has been downloaded.

Then I run ng serve.

Then I open Chrome and go to the localhost URL to access the application. I open Dev tools within Chrome, go into the command line, and type $().jquery to verify that jquery has been installed. When I do that, I get this error:

Uncaught TypeError: Cannot read properties of undefined (reading 'jquery') at <anonymous>:1:4

So, jquery has not been installed.

Any suggestions on how to install jquery with npm install in an Angular application?

UPDATE: When I added node_modules/jquery/dist/jquery.min.js to the "scripts" element in angular.json, the command $().jquery worked in the Dev console terminal and I was able to see the version number of jquery.

Kingamere
  • 9,496
  • 23
  • 71
  • 110
  • Because you install it doesn't mean it's included in your project. It just lays around on your hard drive. How do you include it in the actual project? – cloned Feb 28 '23 at 19:42
  • @cloned Good question. I'm not sure. – Kingamere Feb 28 '23 at 19:43
  • As per comment on your previous question: See: https://stackoverflow.com/questions/30623825/how-to-use-jquery-with-angular – freedomn-m Feb 28 '23 at 19:47
  • @freedomn-m See my latest update, I got it to work by adding the jquery script to the `angular.json` file. – Kingamere Feb 28 '23 at 19:58
  • 1
    Please add as an answer, not as an edit - then you can accept your own answer and hopefully it will help someone else in the future. – freedomn-m Mar 01 '23 at 06:32

1 Answers1

0

When I added node_modules/jquery/dist/jquery.min.js to the "scripts" element in angular.json, the command $().jquery worked in the Dev console terminal and I was able to see the version number of jquery.

Kingamere
  • 9,496
  • 23
  • 71
  • 110