Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find name 'jquery' in angular2

Tags:

I am working on to use the ng2-datetime. Installed through npm, but when I build the solution, I am getting an error that cannot find name 'jQuery'.

I have added the jQuery through npm and also tried to include the jquery library, but the issue still persists. Can anyone tell what else to include? I'm using angular 2.2 with typescript and my IDE is VS2015

app.module.ts

just added the import statement

import { NKDatetimeModule } from 'ng2-datetime/ng2-datetime'; 

and under imports

@NgModule({     imports:[NKDatetimeModule ])} 
like image 813
user3510028 Avatar asked Dec 06 '16 11:12

user3510028


People also ask

Can I use jQuery in Angular?

Adding jQuery to AngularYou need to create an Angular application using ng new command and then you need to 'cd' into that folder to install jQuery via NPM in the development environment.

Why jQuery is not used in Angular?

Selectors and events are usually solved by libraries like React and Angular, so you don't need jQuery to help with browser compability and API differences.

Do you need to install type definitions for jQuery?

Most likely you need to download and include the TypeScript declaration file for jQuery— jquery. d. ts —in your project. Then the compiler will resolve the definitions for jquery automatically.


1 Answers

3 Steps:

  1. Install jQuery. (skip if already installed)

    npm install jquery --save 
  2. Install types for jQuery.

    npm install @types/jquery --save 
  3. Import jQuery in app.module.ts.

    import * as $ from 'jquery'; 
like image 59
Tomas Marik Avatar answered Sep 18 '22 17:09

Tomas Marik