cstefanache / angular2-img-cropper

Angular 2 Image Cropper
MIT License
364 stars 135 forks source link

How to upload the image on click canvas area instead of speared upload button #286

Open dhanarajp opened 6 years ago

dhanarajp commented 6 years ago

How to upload the image on click canvas area instead of speared upload button,

dhanarajp commented 6 years ago

is it possible can bring in this plugin as per below image, i can able to onclick upload dialog opening but i stuck in drag and drop functionality.

image

web-dave commented 6 years ago

do you still need help?

dhanarajp commented 6 years ago

yes, @web-dave

web-dave commented 6 years ago

how do you trigger the input dialog?

<input *ngIf="!settings.noFileInput" #fileInput type="file" accept="image/*" (change)="fileChangeListener($event)">

and in the onMouseDown

@ViewChild("fileInput") fileInput: ElementRef;

  public onMouseDown(event: MouseEvent): void {
    this.cropper.onMouseDown(event);
    if (!this.cropper.isImageSet() && !this.settings.noFileInput) {
      // load img
      this.fileInput.nativeElement.click();
    }
  }
web-dave commented 6 years ago

That's one way. but I'll test it tonight.

dhanarajp commented 6 years ago

Hi @web-dave , i got error: [ts] Property 'isImageSet' does not exist on type 'ImageCropperComponent'.

I am using "ng2-img-cropper": "^0.8.6",