Skip to content

Angular 17 ReferenceError: window is not defined #419

Open
@firegreen

Description

@firegreen

Hi ngx-echarts team, I'm using ngx-echarts 17.1.0 with Angular 17.3.1
When I use a echart component, I meet the following error in the SSR service

ERROR ReferenceError: window is not defined
    at _NgxEchartsDirective.ngOnInit (/root/workspace/takeawaste_exercice/client/node_modules/ngx-echarts/fesm2022/ngx-echarts.mjs:119:5)

because the window variable is not available
here is the html

<echarts [options]="chartOption" class="taw-chart" (chartInit)="onChartInit($event)" [loading]="isLoading"></echarts>

and the ts component

@Component({
  selector: 'app-dashboard',
  standalone: true,
  imports: [CommonModule, NgxEchartsDirective],
  host: {ngSkipHydration: 'true'},
  templateUrl: './dashboard.component.html',
  styleUrl: './dashboard.component.scss',
  providers: [
    provideEcharts(),
  ]
})
export class DashboardComponent {
  chartOption: EChartsOption = {
    xAxis: {
      type: 'time'
    },
    yAxis: {
      type: 'value',
    },
    series: [],
    loading: true
  };
  chart!: ECharts;
  isLoading: boolean = false;

  onChartInit(chart: ECharts)
  {
    this.chart = chart;
  }
}

Is there a way to fix that ?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions