简体   繁体   English

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

[英]Getting error Dropzone already attached with angular Directives

I am using following code for drop zone but i am getting error, i tried to debug it but i am not able to resolve this action plz guide 我正在使用以下代码放置区域,但我收到错误,我试图调试它,但我无法解决此操作PLZ指南

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

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

  throw new Error("Dropzone already attached.");" 

Code:: 码::

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

snippts: 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) {
      }
    }
  };
});

Solved issue by using following code setup. 通过使用以下代码设置解决了问题。

So you can either: 所以你可以:

  1. Turn off autoDiscover globally like this: Dropzone.autoDiscover = false; 像这样全局关闭autoDiscover: Dropzone.autoDiscover = false; , or , 要么
  2. Turn off autoDiscover for specific elements like this: Dropzone.options.myAwesomeDropzone = false; 关闭特定元素的autoDiscover,如下所示: Dropzone.options.myAwesomeDropzone = false;

Reference: 参考:
FAQ on dropzone 关于dropzone的常见问题

Dropzone.autoDiscover = false;
$('#bannerupload').dropzone({
    url: "/upload",
    maxFilesize: 100,
    paramName: "file",
    maxThumbnailFilesize: 5,
    init: function() {      
      this.on('success', function(file, json) {       
        jQuery("input#mediaid").val(json);
      });
    }
  });

Nothing worked for me so i went to the dropzone.js file and change the line that throw an error (i think in many versions it's in line 426): 没有什么对我有用所以我去了dropzone.js文件并更改了引发错误的行(我认为在许多版本中它在第426行):

if (this.element.dropzone) {
    throw new Error("Dropzone already attached.");
  }

so i replace 所以我更换

throw new Error("Dropzone already attached.");

with

return this.element.dropzone;

and it is working 它正在发挥作用

I was facing same issue "Dropzone already attached" because we enabled myDropzone object in the script and were trying to enable again. 我遇到了同样的问题“Dropzone已经附加”,因为我们在脚本中启用了myDropzone对象并尝试再次启用。

For example 例如

if ($('#upl').attr('class')) {

var myDropzone = new Dropzone("#upl", {init: function () {

and again trying to enable it 并再次尝试启用它

 if (jQuery('#password').attr('save_profile')) {
  var myDropzone = new Dropzone("#upl", {init: function () {

with another action. 与另一个行动。

Please check your code. 请检查您的代码。

Put your create dropzone code inside of a try/catch block 将您的create dropzone代码放在try / catch块中

try{
 $('.dropzone').dropzone({
    url: '/upload'
  });
}
catch(error){
    console.log("Catching " + error);
}

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

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