I am trying to use a jquery plugin named imgViewer2(https://github.com/waynegm/imgViewer2) in an Angular 4 project.
I installed npm packages and import jquery successfully and use it well. However when I try to use $(element).imgViewer2(); typescript says cannot find the function. I cannot import the plugin correctly.
What is the way to import and work this plugin?
Thank you very much.
compile errorwhen added code snippet
Solved
Most likely Avaid`s first suggestion,
Added jquery and its plugins refferences to the scripts array in angular-cli.json.
...
scripts: [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/imgViewer2/imgViewer2.min.js"
],
...
then just add the following line to your .ts file to use jQuery.
declare var $: JQuery;
now $ comes with functions and properties which added by the plugin. I do not know if there is a better way to do this but for know this is the painless one for me. Thanks.