question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ERROR TypeError: Cannot read property 'nativeElement' of undefined

See original GitHub issue

ngrx-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:closed
  • Created 2 years ago
  • Reactions:13
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
Mawi137commented, Jul 21, 2021

Hi all, this is fixed in version 4.0.1 as suggested by @danielfsc. Sorry for the inconvenience!

0reactions
sobelfallcommented, Jul 20, 2021

Idem for me. So note that is not blocked

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found