2

I have a problem using jQuery in my project (with Angular and boosted which is a fork of bootstrap). The error is below:

ERROR in folder/containing/my/component.ts: error TS2581: Cannot find name '$'. Do you need to install type definitions for jQuery? Try npm i @types/jquery.

I have installed @types/jquery and jquery, and I have added the script in angular.json file:

"dependencies": {
   // ...
  "boosted": "^4.3.1",
  "bootstrap": "^4.4.1",
},
"devDependencies": {
  // ...
  "typescript": "~3.1.6"
}

"scripts":[
  // ...
  "node_modules/@types/jquery/dist/jquery.slim.d.ts",
  "node_modules/jquery/dist/jquery.js"
]
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
medmoufahim
  • 122
  • 1
  • 3
  • 13

1 Answers1

4

Try to install jquery.

npm install jquery

And then import jquery as $. like below

import * as $ from 'jquery';
Rise
  • 1,493
  • 9
  • 17
  • did $ have a modal method ? I'd like to show a modal: https://getbootstrap.com/docs/4.0/components/modal/#via-javascript – medmoufahim Feb 14 '20 at 14:42