0

after days of research and struggeling I have to ask here to fine someone to clearify the process of importing a library in Typescript.

I was used to just add the tag and everything works fine. Now that I´m trying to build a MEAN-Stack application I don´t figure out how that all works with the definition files and such...

WHAT I TRIED SO FAR:

npm install jquery //terminal root: /project/angular-src
npm install @types/jquery //same directory here

then I importet jQuery in the one of my .ts files

import * as $ from 'jquery'; 

I tried out several variations of this ( installing jQuery and @types/jQuery in the project folder instead of the angular-src folder) but none of it worked for me. I thought it would be that simple but maybe I´m missing something out here. I always get some kind of errors like "Generic type 'xyz' requires x arguments" ( like 200 rows of these )

Hope you can help me explain why this doesnt work and how I can make it work

PS: I found similar questions here before but I didnt really find them helpful as I tried them out with no success

thimos
  • 91
  • 10
  • 1
    The A in MEAN means Angular. Why on Earth would you need jQuery along with Angular? Don't use jQuery, problem solved. – Jeremy Thille Aug 25 '17 at 10:57

2 Answers2

2

You can, in fact, use jQuery with TypeScript. You will need to download the jQuery definition file located here.

With that downloaded, copy the definition file (under the v2 folder, 'index.d.ts' file) to your solution/project.

Once added to your project, you can reference the jQuery definition file by adding this to the top of your .ts file:

///<reference path="../{your-location}/jquery.d.ts"/>

Which should enable jQuery in your TypeScript app.

G.Hunt
  • 1,364
  • 10
  • 20
-1

JQuery and Angular are two separate things either use Angular or JQuery.

Mohhamad Hasham
  • 1,750
  • 1
  • 15
  • 18
  • 1
    ...or even better, don't import jQuery and stick with Angular. – Jeremy Thille Aug 25 '17 at 10:59
  • @JeremyThille quite a sensible approach.But if still the jquery is to be used – Mohhamad Hasham Aug 25 '17 at 11:04
  • You don't need to. If you use Angular, you don't need jQuery. If you _absolutely_ need jQuery, then build a jQuery app, not an Angular app. Don't mix up these two. – Jeremy Thille Aug 25 '17 at 11:07
  • Okay thanks guys...seems like that was the wrong approach... I´ll read myself a bit better into angular 2 then... Can I really get same results as easy with angular than with jquery ( .hide /.show / .datepicker and such functionality with animations) – thimos Aug 25 '17 at 21:00
  • @JohannesBeiser Please upvote the answer so it could help others in the community.And yes you can get angular 2 like JQuery.I would advise you to read some docs before starting a project.Hope that helps – Mohhamad Hasham Aug 25 '17 at 21:19