swimlane / ngx-graph

Graph visualization library for angular

Home Page:https://swimlane.github.io/ngx-graph

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem using ngx-graph as a lazy loaded module

cfrezier opened this issue · comments

Describe the bug
When lazy loading ngxGRaphModule, i have an error:
ERROR NullInjectorError: R3InjectorError(AppModule)[LayoutService -> LayoutService -> LayoutService]:
NullInjectorError: No provider for LayoutService!

In order to try to solve the problem, i tried instanciating the service by myself, but
Module not found: Error: Package path ./lib/graph/layouts/layout.service is not exported from package

To Reproduce
Steps to reproduce the behavior:

  1. Make an example angular app
  2. Add a module
  3. Dynamically load that module using createNgModuleRef
  4. Try to use it

Expected behavior
ngx-graph working

ngx-graph version
^8.0.0

@cfrezier, How did you eagerly load the module?

I have an angular module (let's say it's moduleA) that imports NgxModuleGraph (just like when using loadChildren).

I load that module using code that looks like:

import('./moduleA.module').then(module => {
    const moduleRef = createNgModule(module['ModuleAName'], parentInjector);

    const moduleAComponent = moduleRef.getComponent(); // resolved into a component from module A using ngx-graph

    this.componentRef.createComponent(moduleAComponent);
   
})

It works when NgxGraphModule is imported in the main module, but not when it's only imported in moduleA.

At least if LayoutService was exported from package i could be able to provide it myself.

@cfrezier, In my scenario, I have a main component 'main', then there is a modalComponent which displays a modal, then there is the graphComponent and graphModule which is supposed to be rendered on the modal. When I directly use the NgxGraph module on the main component it works, but if I try to import the GraphModule and create graphComponent on the mainComponent it fails. Isn't it the same as what you just explained above?