cstefanache / angular2-img-cropper

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

when i give set a default image ,it show Cannot read property 'cropper' of undefined #276

Open gaona233 opened 6 years ago

gaona233 commented 6 years ago

it shows Cannot read property 'cropper' of undefined

i give the default imageurl

let image: HTMLImageElement = new Image();
                image.crossOrigin = 'anonymous';
                this.cropper.settings = this.cropperSettings;
                let thatCroper = this.cropper;
                image.onload = () => {
                    thatCroper.setImage(image);
                    if (!this.cropper) {
                        this.cropper = thatCroper;
                    }
                };
                image.src = this.wallpaperCollection.Cover;
  fileChangeListener($event) {
        this.eventFile = $event;
        this.data1 = {};
        let image: any = new Image();
        let file: File = $event.target.files[0];
        let myReader: FileReader = new FileReader();
        let that = this.cropper;
        this.fileName = file.name;
        myReader.onloadend = function (loadEvent: any) {
            image.src = loadEvent.target.result;
            that.cropper.setImage(image);

        };
        myReader.readAsDataURL(file);
    }

i have no ideal

anouarcharif commented 6 years ago

Hello,

Instead of this: let that = this.cropper;

Write this: let that = this;