Creating a directive for a external library in angular 2 -
i starting out angular 2, , have finished doing basic quick start. playing around , have hit bit of block. trying use dropzone.js.
i read somewhere else use external libraries adding script, , doing in component:
//index.html <script src="node_modules/dropzone/dropzone.js"></script> //app.component.ts declare var dropzone: any; ... constructor(){ var mydropzone = new dropzone("div#myid", { url: "/file/post"}); //i added div same id here template. }
this didn't work me. tried use this angular 1 directive dropzone.js reference creating 1 angular 2, bit lost, never worked angular 1 before.
after having added dropzone.js file in index.html
file:
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.2.0/dropzone.js"></script>
you link root element of component:
@component({ selector: 'dropzone', template: ` <div>drop down area</div> ` }) export class dropzonecomponent { constructor(eltref:elementref) { new dropzone(eltref.nativeelement, { url: "/file/post"}); } }
here plunkr describing this: https://plnkr.co/edit/gv9fuwqalb7g7v7zxwd4?p=preview.
Comments
Post a Comment