ERROR TypeError: Cannot read property 'nativeElement' of undefined
See original GitHub issuengrx-image-cropper version: 4.0.0 Angular: v12.1.1 Browser: Edge 91.0.864.64 When it happens: All the time What to do to produce the error: Nothing, the error simply appears when the component is rendered.
Code
import { Component } from '@angular/core';
import { ImageCroppedEvent, LoadedImage } from 'ngx-image-cropper';
@Component({
selector: 'app-change-avatar',
templateUrl: './change-avatar.component.html',
styleUrls: ['./change-avatar.component.less'],
})
export class Component {
constructor() {}
imageChangedEvent: any = '';
croppedImage: any = '';
fileChangeEvent(event: any): void {
this.imageChangedEvent = event;
}
imageCropped(event: ImageCroppedEvent) {
this.croppedImage = event.base64;
}
imageLoaded(image: LoadedImage) {
// show cropper
}
cropperReady() {
// cropper ready
}
loadImageFailed() {
// show message
}
}
Template
<input type="file" (change)="fileChangeEvent($event)" />
<image-cropper
[imageChangedEvent]="imageChangedEvent"
[maintainAspectRatio]="true"
[aspectRatio]="4 / 3"
format="png"
(imageCropped)="imageCropped($event)"
(imageLoaded)="imageLoaded($event)"
(cropperReady)="cropperReady()"
(loadImageFailed)="loadImageFailed()"
></image-cropper>
<img [src]="croppedImage" />
Error Stack
core.js:6456 ERROR TypeError: Cannot read property 'nativeElement' of undefined
at CropperPositionService.resetCropperPosition (ngx-image-cropper.js:994)
at ImageCropperComponent.resetCropperPosition (ngx-image-cropper.js:1659)
at ImageCropperComponent.ngOnChanges (ngx-image-cropper.js:1382)
at ImageCropperComponent.rememberChangeHistoryAndInvokeOnChangesHook (core.js:1498)
at callHook (core.js:2536)
at callHooks (core.js:2495)
at executeInitAndCheckHooks (core.js:2446)
at selectIndexInternal (core.js:8428)
at Module.ɵɵadvance (core.js:8411)
at ChangeAvatarComponent_Template (change-avatar.component.html:14)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:13
- Comments:12 (1 by maintainers)
Top Results From Across the Web
viewChild not working - cannot read property nativeElement of ...
I'm trying to access a native element in order to focus on it when another element is clicked (much like the html attribute...
Read more >Cannot read property 'nativeElement' of undefined - Ionic Forum
When is initializeMap getting called? If it's getting called too early, like during ngOnInit , the element won't be ready yet. You'll need...
Read more >Angular2: Cannot read property 'nativeElement' of undefined
This was working fine with 1.1.0-beta4 using (grid-ready)="onGridReady($event)" event. Now that I've moved to 1.1.0 final, I can't seem to ...
Read more >Cannot read property 'nativeElement' of undefined and ...
Cannot read property 'nativeElement' of undefined and IntegrationError: We could not retrieve data from the specified Element.
Read more >ContentChild: Cannot read property 'nativeElement' of undefined
This tutorial guides you on how to resolve @ContentChild TypeError: : Cannot read property 'nativeElement' of undefined error that you are ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi all, this is fixed in version 4.0.1 as suggested by @danielfsc. Sorry for the inconvenience!
Idem for me. So note that is not blocked