简体   繁体   English

使用外部JS库Angular 2

[英]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 我想在angular 2项目中使用简单的示例dropzone js: http : //www.dropzonejs.com/examples/simple.html

Is there an easy way to use the js for simple drag and drop functionality? 有没有一种简单的方法可以将js用于简单的拖放功能? 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. 并从index.html中的node_modules引用脚本,但似乎不起作用。

Plunkr: http://plnkr.co/edit/Gk2xtoH1FhOe6hko6z8K?p=preview 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: 当前,将外部库包含到angular 2项目中的最简单方法如下:

1) include it in your HTML file as a script tag 1)将其作为脚本标签包含在HTML文件中

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

2) To use the library you must add the following to one of your ts/js files: 2)要使用该库,必须将以下内容添加到ts / js文件之一:

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: 其中libraryVar是要包含的库中函数的名称,例如,要包含jQuery,可以使用:

declare let $:any;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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