cstefanache / angular2-img-cropper

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

ng2-cropper is not working for select the same image #265

Closed bhutiyaDilip closed 6 years ago

bhutiyaDilip commented 6 years ago

when i select the same image form file upload than it's not working. and if i put the click event ested of change than its give me a erroe for file Reader

TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'.
    at _global.(anonymous function).(anonymous function) [as readAsDataURL] (https://npmcdn.com/zone.js@0.6.12?main=browser:952:61)
    at AppComponent.fileChangeListener (https://run.plnkr.co/preview/cj9ql6do400083b5snaoxys2l/app/app.component.ts!transpiled:69:18)
    at _View_AppComponent0._handle_click_24_0 (AppComponent.ngfactory.js:276:28)
    at eval (https://npmcdn.com/@angular/core@2.0.0-rc.5/bundles/core.umd.js:12718:28)
    at eval (https://npmcdn.com/@angular/platform-browser@2.0.0-rc.5/bundles/platform-browser.umd.js:1836:40)
    at eval (https://npmcdn.com/@angular/platform-browser@2.0.0-rc.5/bundles/platform-browser.umd.js:1913:115)
    at ZoneDelegate.invoke (https://npmcdn.com/zone.js@0.6.12?main=browser:323:29)
    at Object.onInvoke (https://npmcdn.com/@angular/core@2.0.0-rc.5/bundles/core.umd.js:9245:45)
    at ZoneDelegate.invoke (https://npmcdn.com/zone.js@0.6.12?main=browser:322:35)
    at Zone.runGuarded (https://npmcdn.com/zone.js@0.6.12?main=browser:230:48)

can you please suggest me?

bhutiyaDilip commented 6 years ago

i got the solutions for this. it's working well for me.

<button class="btn"  (click)="clear()">Cancle</button>

clear( ) {
       let defaultValue: any = '';
       const controlPic = <FormArray>this.myForm.controls['profile_picture'];
       controlPic.setValue( defaultValue );
   }

thanks.