zefoy / ngx-dropzone-wrapper

Angular wrapper library for Dropzone
MIT License
174 stars 51 forks source link

How to get reference to dropzone component? #71

Closed eliavmaman closed 6 years ago

eliavmaman commented 6 years ago

i have a form for create user, and i want to save the images of that user after saving user. so i configure autoProcessQeueu =false. in the constructor

@ViewChild(DropzoneComponent) componentRef: DropzoneComponent;
this.assetService.addAsset(asset).subscribe(data => {
      if (data.success) {
        let prop = data.property;
        this.DROPZONE_CONFIG.url = 'http://localhost:3000/properties/property/' + prop._id + '/upload';
        this.myDropzone.processQueue().then((data) => {
          console.log(data);
        });

        //this.flashMessage.show('Added new asset', {cssClass: 'alert-success', timeout: 3000});
        //this.router.navigate(['/dashboard']);
      } 
    });

i want to manually trigger the processQueue.

How to do that?

sconix commented 6 years ago

Calling dropzone() from the wrapper directiveRef returns the dropzone instance. This is mentioned in the README and there is an example in the example app how to access the directiveref.

eliavmaman commented 6 years ago

i changed my code to

@ViewChild(DropzoneDirective) directiveRef: DropzoneDirective;
 this.assetService.addAsset(asset).subscribe(data => {
      if (data.success) {
        let prop = data.property;
        this.directiveRef.config.method='post';
        this.directiveRef.config.url = 'http://localhost:3000/properties/property/' + prop._id + '/upload';
        this.directiveRef.dropzone.processQueue();
       } 
    });

image

really dont know what to do... :(

sconix commented 6 years ago

You can't just modify the config of the directive it wont update to the Dropzone. Everything from that point is pure Dropzone so you do exactly like you would do with Dropzone, you use the dropzone instance directly and set its options (if its the way Dropzone is supposed to be used, I am not an expert of Dropzone so don't know how to use the processQueue).

eliavmaman commented 6 years ago

any one can help ?

minuz commented 6 years ago

@eliavmaman,

It's a bit hard to debug without a working example, but I have the feeling the configs are not being passed all the way to the dropzone instance when you modify programatically. You could modify the properties after you get the dropzone instance from the directive.

Have you tried this?

this.assetService.addAsset(asset).subscribe(data => {
      if (data.success) {
        let prop = data.property;
        let dropzone =  this.directiveRef.dropzone();

        dropzone.options.url =  'http://localhost:3000/properties/property/' + prop._id + '/upload';
        dropzone.processQueue();
       } 
    });