获取错误Dropzone已经附加了角度指令

ana*_*nam 10 javascript angularjs dropzone.js

我正在使用以下代码放置区域,但我收到错误,我试图调试它,但我无法解决此操作PLZ指南

http://jsfiddle.net/anam123/rL6Bh/

 -------------------> "Error: Dropzone already attached.

  throw new Error("Dropzone already attached.");" 
Run Code Online (Sandbox Code Playgroud)

码::

https://gist.github.com/compact/8118670

snippts:

 /**
 * An AngularJS directive for Dropzone.js, http://www.dropzonejs.com/
 * 
 * Usage:
 * 
 * <div ng-app="app" ng-controller="SomeCtrl">
 *   <button dropzone="dropzoneConfig">
 *     Drag and drop files here or click to upload
 *   </button>
 * </div>
 */

angular.module('dropzone', []).directive('dropzone', function () {
  return function (scope, element, attrs) {
    var config, dropzone;

    config = scope[attrs.dropzone];

    // create a Dropzone for the element with the given options
    dropzone = new Dropzone(element[0], config.options);

    // bind the given event handlers
    _.each(config.eventHandlers, function (handler, event) {
      dropzone.on(event, handler);
    });
  };
});

angular.module('app', ['dropzone']);

angular.module('app').controller('SomeCtrl', function ($scope) {
  $scope.dropzoneConfig = {
    'options': { // passed into the Dropzone constructor
      'url': 'upload.php'
    },
    'eventHandlers': {
      'sending': function (file, xhr, formData) {
      },
      'success': function (file, response) {
      }
    }
  };
});
Run Code Online (Sandbox Code Playgroud)

ana*_*nam 22

通过使用以下代码设置解决了问题.

所以你可以:

  1. 全局关闭autoDiscover,如下所示:Dropzone.autoDiscover = false;,或
  2. 关闭特定元素的autoDiscover,如下所示: Dropzone.options.myAwesomeDropzone = false;

参考:
dropzone的常见问题解答

  • 我面临同样的问题......我试过`Dropzone.autoDiscover = false;`和另一个选项......但是我得到同样的错误 (5认同)