Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

317
Vistas
Angular 2 - AOT - Calling function 'ChartModule', function calls not supported

I am losing my mind and hair over this. I am importing HighCharts in Angular 2 but need to require some of its extra libraries. So far in my code I have

import {ChartModule} from 'angular2-highcharts';
@NgModule({
....
imports:[
ChartModule.forRoot(require('highcharts'), require('highcharts/modules/drilldown'))})
]

But I keep getting this error

ERROR in Error encountered resolving symbol values statically. Calling function 'ChartModule'. function calls are not supported. Consider replacing the function or lambda with a reference to an exported fucntion.

So I tried

export function highchartsRequire:any {
   return{
     require('highcharts'), 
     require('highcharts/modules/drilldown')
   }
}
...
ChartModule.forRoot(highchartsRequire())

Still doesn't work. Any ideas?

Using angular 2 angular cli: 1.0.0-beta.30

UPDATE - got it partially working thanks to JayChase

This works

export function highchartsFactory() {
      return require('highcharts');

    }

But I cannot require two at a time

declare var require: any;
export function highchartsFactory() {
  return function () {
    require('highcharts');
    require('highcharts/modules/drilldown')
  };
}

@NgModule({
  imports: [
    ChartModule
  ],
  providers: [
    {
      provide: HighchartsStatic,
      useFactory: highchartsFactory
    }
  ],

Any ideas? Thank you.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There is an issue open for this and a workaround here using an exported function.

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { FormsModule } from '@angular/forms';
    import { HttpModule } from '@angular/http';
    import { ChartModule } from 'angular2-highcharts';
    import { HighchartsStatic } from 'angular2-highcharts/dist/HighchartsService';

    import { AppComponent } from './app.component';

    declare var require: any;

    export function highchartsFactory() {
      const hc = require('highcharts');
      const dd = require('highcharts/modules/drilldown');
      dd(hc);

      return hc;
    }

    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        FormsModule,
        HttpModule,
        ChartModule
      ],
      providers: [
        {
          provide: HighchartsStatic,
          useFactory: highchartsFactory
        }
      ],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda