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: View Container not found! ngUpgrade needs to manually set this via setRootViewContainer or setGlobalRootViewContainer.

See original GitHub issue

Describe the bug If have an angular 9 app running with ngUpgrade in usage. Since the upgrade from angular 8.2.14 to 9.1.2 and ngx-charts 12.0.1 to 14.0.0 the error Error: View Container not found! ngUpgrade needs to manually set this via setRootViewContainer or setGlobalRootViewContainer. is thrown, when hovering over a line chart.

Expected behavior The chart shall not throw an exception.

Screenshots image

ngx-charts version 14.0.0

Additional context If this is not a bug a description of how to fix this would be really helpful.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

4reactions
mvandenbrinkcommented, Jul 16, 2020

Thanks @medi6 , this removes the error indeed. Working with a base component, it was enough to only pass the viewContainerRef.

import { TooltipService } from '@swimlane/ngx-charts';

export class BaseComponent implements OnChanges, OnInit {
...
  private chartToolTipService : TooltipService;
  readonly viewContainerRef: ViewContainerRef;

  constructor(
    private injectorObj: Injector,
  ) {
    this.chartToolTipService = this.injectorObj.get(TooltipService);
    this.viewContainerRef = this.injectorObj.get(ViewContainerRef);
  }

  ngOnInit(): void {
    this.chartToolTipService.injectionService.setRootViewContainer(this.viewContainerRef);
    ...
  }
  
  ...
}

export class MyChartComponent extends BaseComponent {
  constructor(
    public injector: Injector,
  ) {
    super(injector);
  }
}
3reactions
medi6commented, Jul 15, 2020

Hi, after spending a little time on it, I’ve got a solution.

1/ inject TooltipService in your component import {TooltipService} from '@swimlane/ngx-charts'; 2/ In component’s constructor add : private chartToolTipService : TooltipService, private viewContainerRef: ViewContainerRef
3/ set the ViewContainerRef in ngOnInit. You can use the ViewContainerRef of your component, but It’s better to use your root ViewContainerRef because of superpositions errors. In my case (ngUpgrade) It’s a little more complicated : this.chartToolTipService.injectionService.setRootViewContainer(this.parentContainer||this.coreServicesProvider.mainViewService.mainViewContainer||this.viewContainerRef);

And it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular2 Dynamic Component Injection in Root - Stack Overflow
... return rootComponents[0]; throw new Error('View Container not found! ngUpgrade needs to manually set this via setRootViewContainer.
Read more >
Angular Debugging "Expression has changed": Explanation ...
We are going to give a complete explanation about this error. We will learn why it occurs, how to debug it consistently and...
Read more >
Preparing for the Angular 1 8 Upgrade in Primo - YouTube
Preparing for the Angular 1 8 Upgrade in Primo - Americas and EMEA. 307 views 4 months ago. ExLibrisLtd. ExLibrisLtd. 3.11K subscribers.
Read more >
Upgrading from AngularJS to Angular
The upgrade module in Angular has been designed to make incremental ... This not only makes components easy to navigate and find, but...
Read more >
swimlane/ngx-graph - Gitter
I tried to change the svg.ngx-charts { cursor: pointer} in my component's css ... I'm styling light theme, but I can not change...
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