Open limpep opened 7 years ago
Same issue here... my component is placed in modal...
Same issue here. I'm using this component inside ng2-bootstrap-modal. The image data is obtained from a file upload and then I try to init the cropper inside the modal without success. I've tried to put setImage function inside ngAfterViewInit() or ngOnInit() but the result is the same.
Check if you have added 'ImageCropperComponent' in your ngModule declarations.
How did you guys resolve this?
For me it works only if I do not set this.cropperSettings.noFileInput = true; But then I cant style the Input field which is not very desirable
In my case it worked adding the settings to the cropper object at the end of ngOnInit()
this.cropper.settings = this.cropperSettings;
Hello,
I am working in something similar, working for me with the following code:
let image = new Image();
image.src = this.model[this.key];
image.crossOrigin = 'Anonymous';
image.onload = () => {
this.cropper.setImage(image);
};
you need to be sure that the image is loaded, before to set it.
I ended up using the base64 provided to me by my backend system.
Same problem here, trying to upload an image from a component and passing it to a modal (bsx) and then add it to the image cropper.
Just crossed this frustrating issue and spent ~4 frustrating hours trying to find a solution. The problem is that cropper is inside the modal and is never initiated with viewchild:
@ViewChild('cropper', undefined)
cropper:ImageCropperComponent;
This describes the problem https://stackoverflow.com/questions/34947154/angular-2-viewchild-annotation-returns-undefined , tried all the suggestions but nothing works for this particular case.
After a coffe this came to my mind and works for me:
<div class="file-upload">
<span class="text">upload</span>
<input id="custom-input" type="file" (change)="fileChangeListener($event, cropper)">
</div>
fileChangeListener($event, cropperComp: ImageCropperComponent) {
this.cropper = cropperComp;
let image = new Image();
var file:File = $event.target.files[0];
var myReader:FileReader = new FileReader();
var that = this;
myReader.onloadend = function (loadEvent: any) {
image.src = loadEvent.target.result;
that.cropper.setImage(image);
};
myReader.readAsDataURL(file);
}
@analuisamartins thank you!
@analuisamartins working for me, thank you!
I had the same issue when using this.cropperSettings.noFileInput = true;
. A simple omission from the example was the issue for me: #cropper
selector in the view. It's right there in the Customizing Image cropper example. Added that and it works as expected.
In my case, it was just an error importing Image, I was sending a wrong image model.
@analuisamartins thank you !!!! it's working very very fine...............................
it happened to me when I removed the this.data = {}; of the constructor, just add it again.
Hi,
I am trying to load the image that I get from the server in my loadImage method but I keep getting the following error Cannot read property 'setImage' of undefined. Not sure why, any help would be much appreciated.
Here is my code below