简体   繁体   中英

Using an External JS Library Angular 2

I want to use the simple example dropzone js in an angular 2 project: http://www.dropzonejs.com/examples/simple.html

Is there an easy way to use the js for simple drag and drop functionality? I tried adding installing using:

npm i dropzone --save

And referencing the script from node_modules in index.html, but it doesn't seem to work.

Plunkr: http://plnkr.co/edit/Gk2xtoH1FhOe6hko6z8K?p=preview

Currently, The easiest way to include an external library into an angular 2 project is as follows:

1) include it in your HTML file as a script tag

<script src="js/your-library.js"></script>

2) To use the library you must add the following to one of your ts/js files:

declare var libraryVar: any;

or

var libraryVar

Where libraryVar is the name of a function from the library you're including, so for example, to include jQuery, you would use:

declare let $:any;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM