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.

Cannot read property 'nativeElement' of undefined when View is undefined

See original GitHub issue

I’m submitting a … (check one with “x”)

[X ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here

Current behavior I’m using the latest version of ngx-charts with Angular 4.0.0 and I get an error when trying to set view to undefined to get the chart at parent’s div dimensions.

ChartWindowComponent.html:52 ERROR TypeError: Cannot read property 'nativeElement' of undefined at LineChartComponent../src/common/base-chart.component.ts.BaseChartComponent.getContainerDims (index.js:9031) at LineChartComponent../src/common/base-chart.component.ts.BaseChartComponent.update (index.js:9015) at LineChartComponent../src/line-chart/line-chart.component.ts.LineChartComponent.update (index.js:14596) at LineChartComponent../src/common/base-chart.component.ts.BaseChartComponent.ngOnChanges (index.js:9004)

Expected behavior Just get the chart to fit to the parent container size.

  • ngx-charts version: 5.1.2
  • Angular version: 4.0.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
caotuiit1997commented, Apr 2, 2018

I don’t know if you guy had resolved this issue: MatSelect.html:1 ERROR TypeError: Cannot read property ‘nativeElement’ of undefined. I found a solution by setTimeOut and waited for all view init.

ngAfterViewInit() {
    setTimeout(()=>{
      this.loadingMap = true;
      if (this.loadingMap == true) {
        this.loadMap();
      }
    },3000);
  }

It worked for me perfectly!

1reaction
devangptechuzcommented, Jul 2, 2020

you should use ngAfterviewInit(){ } instead of timeout()

Read more comments on GitHub >

github_iconTop Results From Across the Web

viewChild not working - cannot read property nativeElement of ...
I try to console. log the nativeElement in ngAfterViewInit() so that it is loaded but it still throws the error.
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 >
Cannot read property 'element' of undefined - Angular
Cannot read property 'element' of undefined ; February 20, 2020 02:53 AM. Hi Ravikumar,. Those errors are for Angular 8, not Angular 9,...
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