0

I'm trying to use dragula in angular2 app with angular-cli.

<script src="vendor/dragula/dist/dragula.min.js"></script>

<script src="vendor/es6-shim/es6-shim.js"></script>
<script src="vendor/systemjs/dist/system-polyfills.js"></script>
<script src="vendor/angular2/bundles/angular2-polyfills.js"></script>
<script src="vendor/systemjs/dist/system.src.js"></script>
<script src="vendor/rxjs/bundles/Rx.js"></script>

<script src="vendor/angular2/bundles/angular2.dev.js"></script>
<script src="vendor/angular2/bundles/http.dev.js"></script>
<script src="vendor/angular2/bundles/router.dev.js"></script>

<script>
System.config({
  packages: {
    app: {
      format: 'register',
      defaultExtension: 'js'
    }
  },
  paths: {
    dragula: 'vendor/dragula/dist/dragula.min.js'
  }
});
System.import('app.js').then(null, console.error.bind(console));
</script>

When I import dragula like this:

import * as dragula from 'dragula';

and try to use I get dragula is not a function error

Rakhat
  • 4,783
  • 4
  • 40
  • 50

1 Answers1

0

In fact the dragula variable isn't actually a function. Here is the content of this object:

Object {__useDefault: true}
  __useDefault:true
  default: dragula(initialContainers, options)

You should use the following to import and use the dragula function:

import * as dragula from 'dragula';

dragula.default(...);

See this plunkr: https://plnkr.co/edit/J0POatroAhqfV9LDQQ5g?p=preview.

Thierry Templier
  • 198,364
  • 44
  • 396
  • 360