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

纵然是瞬间 提交于 2019-11-29 04:03:11

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 { }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!