Bhetzie
Bhetzie

Reputation: 2932

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

Upvotes: 0

Views: 237

Answers (1)

Gerard Simpson
Gerard Simpson

Reputation: 2126

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;

Upvotes: 2

Related Questions