Jquery carousel method error in Angular2/typescrip

2019-09-06 12:39发布

问题:

I have installed jquery and imported it properly.

Somewhere in my app, I have a line as below,

 $('#myCarousel').carousel("next");

When I do npm start, it throws below error

Property 'carousel' does not exist on type 'JQuery'.

in Typescript if do $('#myCarousel')., ** it shows appropriate **intellisense but this method is not listed.

If I comment that error generating line, do npm start everything works and then if I uncomment that line and refresh it, it will work.

Its a typescript compiling error. How to resolve it????

回答1:

After Angular's Final Release,

1) add following npm packages

  npm install --save-dev @types/jquery
  npm install --save-dev @types/bootstrap

2) in tsconfig.json add following entries in types array,

  "types": [
             "jquery",
             "bootstrap",  
           ]

And now you are good to go.