zefoy / ngx-dropzone-wrapper

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

How to use @ViewChild for ng-template dropzone? #106

Open krutika20 opened 6 years ago

krutika20 commented 6 years ago

this.drpzone.directiveRef.dropzone().processQueue();

directiveRef for invalid component, because dropzone is defined in ng-template how to use this functionality for ng-template?

sconix commented 6 years ago

Check the example app.

krutika20 commented 6 years ago

Can you please check my Code? html code <ng-template #content1 let-c="close" let-c="dismiss" id="emailModel">

<dropzone #fileInput="ngxDropzone" (complete)="onUploadComplete($event)" [config]="dropzoneConfig" [message]="'Click or drag images here to upload'" (error)="onUploadError($event)" (success)="onUploadSuccess($event)">

component.ts import { DropzoneConfigInterface,DropzoneModule ,DropzoneComponent , DropzoneDirective } from 'ngx-dropzone-wrapper';

export class DetailpurchaseComponent implements OnInit{

@ViewChild(DropzoneComponent) fileInput:DropzoneComponent;
dropzoneConfig:DropzoneConfigInterface;

}

sendEmail(emailData){ console.log(this.fileInput.directiveRef.dropzone.getQueuedFiles().length); //this.fileInput.directiveRef.dropzone.processQueue(); console.log(emailData); }

Module.ts import { DropzoneModule } from 'ngx-dropzone-wrapper'; import { DropzoneConfigInterface,DropzoneComponent } from 'ngx-dropzone-wrapper';

const DROPZONE_CONFIG_PROD: DropzoneConfigInterface = { dictRemoveFileConfirmation: "Are you sure you want to remove this?", // Change this to your upload POST address: maxFilesize: 300, method: 'post',

headers:{'Cache-Control': null, 'X-Requested-With': null}, paramName: 'media', addRemoveLinks: true, createImageThumbnails: true, };

@NgModule({ declarations: [

], imports: [DropzoneModule.forChild()], providers: [

] ,

})

krutika20 commented 6 years ago

And i am getting error Cannot read property 'directiveRef' of undefined becuase my fileinput is defined in ng-template, i have example app but i am not clear with that code that how to solve this error.

Please reply as soon as possible.

sconix commented 6 years ago

Are you using some old version? Since new versions don't have the forChild function so I believe you are using some really old version that does not even have the directiveRef support in.

krutika20 commented 6 years ago

directiveRef supported if my dropzone component is not in ng-template.

sconix commented 6 years ago

Ah ok, then all should be ok. I guess you need to seek support from Angular forums then I have not needed to reference components inside of template so can not help you with that. I mean you might have better luck with Angular forums since ViewChild usage is specific to library its common Angular feature.

marcioveiga16 commented 5 years ago

any fix for this?

mhonjester commented 2 years ago

any solution for this ?