0

I use Angular 9 universal, Typescript version ~3.7.5 and I installed both jQuery and its type definition using:

npm i jquery npm i @types/jquery

Then I added jQuery in the types field in the tsconfig file. However after I run the app I still get this error:

Cannot find name '$'. Do you need to install type definitions for jQuery? Try "npm i @types/jquery" and then add "jquery" to the types field in your tsconfig.`

What is the problem here?

1
  • 1
    Did you ran npm i jquery npm i @types/jquery this in one line or one after another. Commented Mar 26, 2020 at 14:03

1 Answer 1

1

Install jQuery

npm install --save jquery

Install jQuery Definition

npm install -D @types/jquery

than include jquery in a component like this

import * as $ from 'jquery';

Example:

$(selector).hide(); 

OR

declare var jQuery: any;

Example:

jQuery(selector).hide(); 
Sign up to request clarification or add additional context in comments.

6 Comments

How do you know about defining a $ variable? there is no source for it.
I tried it, and there was no error at compile time but there is one at runtime: ` core.js:5871 ERROR TypeError: $ is not a function`
@roya Which solution first or second? If first then please replace “$” with “jQuery” in the script. I had the same error and fixed it or try with the second solution.
Depending on angular.io/guide/using-libraries, I added the associated script and css files to the "scripts" and "styles" array in angular.json. then i used $("p").tooltip();
Please check this link: angularjswiki.com/angular/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.