ng2-image-upload: Delete Image Error

When Image Limit completed, then only the clear button is visible. If I remove all the images or A single image, I’m getting an error from the component. Also, delete event is not fired.

UploadDocumentComponent.html:18 ERROR TypeError: Cannot read property 'nativeElement' of undefined at ImageUploadComponent.deleteAll (image-upload.component.js:85) at Object.eval [as handleEvent] (ImageUploadComponent.html:27) at handleEvent (core.js:13589) at callWithDebugContext (core.js:15098) at Object.debugHandleEvent [as handleEvent] (core.js:14685) at dispatchEvent (core.js:10004) at eval (core.js:10629) at HTMLButtonElement.eval (platform-browser.js:2628) at ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:4751)

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 2
  • Comments: 16

Most upvoted comments

The problem is the parameter [max]=“xxxxx” I solve my problem, remove the parameter and add the parameter [beforeUpload]=“onBeforeUpload”. private fileCounter = 0;

onBeforeUpload = (metadata: UploadMetadata) => { if (this.fileCounter >= xxx) { metadata.abort = true; } else { this.fileCounter++; } return metadata; };

@aberezkin , @UncleDave Can you please publish this update?

Publish it on npm, please

Publish it on npm, please

I’ve the same problem. Think had resolved this problem but no published in the npm yet.

I found a workaround for this issue, just call contents of deleteAll() method directly in your code:

...
@ViewChild('logoUploader') logoUploader: ImageUploadComponent;
...
// this.logoUploader.deleteAll();
this.logoUploader.files.forEach(f => this.logoUploader.removed.emit(f));
this.logoUploader.files = [];
this.logoUploader.fileCounter = 0;
...