[英]ngx-image-cropper imageloaded() not passing any image data to typescript file event method
I'm using ngx-image-cropper to load and crop images.我正在使用ngx-image-cropper加载和裁剪图像。 According to the docs there is
根据文档有
(imageLoaded)="imageLoaded($event)"
but when I step into the typescript to debug the method 'imageLoaded()' image is undefined.但是当我进入 typescript 调试方法“imageLoaded()”时,图像未定义。 It's not passing anything to the method.
它没有向该方法传递任何东西。
In the library's code is see this在图书馆的代码中看到这个
imageLoaded: EventEmitter<void>;
so it looks like the event doesn't pass anything, even though the docs say it does.所以看起来事件没有通过任何东西,即使文档说它确实如此。 Am I missing something here in terms of how I access the loaded image?
关于如何访问加载的图像,我在这里遗漏了什么吗?
QUESTION - The docs don't show anything being passed in the html, should I pass in the '$event'?问题- 文档没有显示 html 中传递的任何内容,我应该传递“$event”吗?
imageLoaded(image: HTMLImageElement) { // image is undefined }
<image-cropper [imageChangedEvent]="imageChangedEvent" [maintainAspectRatio]="true" [aspectRatio]="4/3" format="png" [transform]="transform" (imageCropped)="imageCropped($event)" (imageLoaded)="imageLoaded($event)" (loadImageFailed)="loadImageFailed()"> </image-cropper>
Exactly!确切地! In order to have event inside method you need to pass '$event' from html parameter
为了在方法中包含事件,您需要从 html 参数中传递“$event”
You do need to pass $event to the function that will be called, although the docs don't currently show that:您确实需要将 $event 传递给将被调用的 function,尽管文档目前没有显示:
(imageLoaded)="imageLoaded($event)"
Then in the called function, you can obtain data like this (refer to the docs for LoadedImage):然后在被调用的 function 中,你可以获得这样的数据(参考 LoadedImage 的文档):
imageLoaded( img: LoadedImage ) {
const width = img.original.size.width;
const height = img.original.size.height;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.