xieziyu/ngx-echarts

NgxEchartsModule.forChild() not working after upgrading to ngx-echarts 8.0.0 and Angular 13

jkasperbl opened this issue · 3 comments

I am creating an Angular component library to use on a variety of related projects and chose Echarts for our charting solution. I have a global app module which imports NgxEchartsModule.forRoot():

import { NgModule } from "@angular/core";
import { NgxEchartsModule } from "ngx-echarts";

@NgModule({
    imports: [
        NgxEchartsModule.forRoot({
            echarts: () => import('echarts' as 'echarts')
        })
    ]
})
export class GlobalModule { }

I also have a chart component which acts as a simple wrapper. This component is in its own module which imports NgxEchartsModule.forChild():

@NgModule({
    imports: [
        CommonModule,
        NgxEchartsModule.forChild()
    ],
    declarations: [ChartComponent],
    exports: [ChartComponent]
})
export class ChartComponentModule { }

This was working fine with Angular 12 and ngx-echarts 7.0.1, but after upgrading I can no longer build as I get the following error, referring to the NgxEchartsModule.forChild() line:

Value at position 1 in the NgModule.imports of ChartComponentModule is not a reference
Value could not be determined statically.

Unable to evaluate this expression statically.
A value for 'forChild' cannot be determined statically, as it is an external declaration.

Am I doing something wrong or is there a bug here that needs to be fixed? Any prompt assistance would be greatly appreciated.

FYI I was able to work around this by making the following change to ComponentChartModule:

@NgModule({
    imports: [
        CommonModule,
        {
            ngModule: NgxEchartsModule
        }
    ],
    declarations: [ChartComponent],
    exports: [ChartComponent]
})
export class ChartComponentModule { }

I found that solution by reading the source code for forChild here. That's easy enough, but it would still be better to find a way to make this method work.

Thanks for reporting this issue, please try to upgrade v8.0.1

@xieziyu That did the trick. Thanks for the quick solution!