使用带有systemjs的dragula

时间:2016-04-27 09:05:42

标签: angular systemjs dragula

我正在尝试使用angular-cli在angular2 app中使用dragula。

<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>

当我像这样导入dragula时:

import * as dragula from 'dragula';

并尝试使用我得到dragula is not a function错误

1 个答案:

答案 0 :(得分:0)

实际上dragula变量实际上并不是一个函数。以下是此对象的内容:

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

您应该使用以下内容导入并使用dragula函数:

import * as dragula from 'dragula';

dragula.default(...);

请参阅此plunkr:https://plnkr.co/edit/J0POatroAhqfV9LDQQ5g?p=preview