gpt4 book ai didi

angular - NullInjectorError : No provider for InjectionToken NGX_ECHARTS_CONFIG

转载 作者:行者123 更新时间:2023-12-03 23:59:25 26 4
gpt4 key购买 nike

我正在开发 Angular 应用程序,当我打开我的项目时,它给了我如下错误

ERROR NullInjectorError: R3InjectorError(IndexModule)[InjectionToken NGX_ECHARTS_CONFIG -> InjectionToken NGX_ECHARTS_CONFIG -> InjectionToken NGX_ECHARTS_CONFIG -> InjectionToken NGX_ECHARTS_CONFIG]: 
NullInjectorError: No provider for InjectionToken NGX_ECHARTS_CONFIG!
at NullInjector.get (http://localhost:4200/vendor.js:71789:21)
at R3Injector.get (http://localhost:4200/vendor.js:84254:29)
at R3Injector.get (http://localhost:4200/vendor.js:84254:29)
at R3Injector.get (http://localhost:4200/vendor.js:84254:29)
at NgModuleRef$1.get (http://localhost:4200/vendor.js:100306:31)
at R3Injector.get (http://localhost:4200/vendor.js:84254:29)
at NgModuleRef$1.get (http://localhost:4200/vendor.js:100306:31)
at Object.get (http://localhost:4200/vendor.js:97671:29)
at getOrCreateInjectable (http://localhost:4200/vendor.js:75308:31)
at Module.ɵɵdirectiveInject (http://localhost:4200/vendor.js:87509:10)
尝试安装 ngx-echarts
npm install echarts -S
npm install ngx-echarts -S
仍然得到相同的上述错误

最佳答案

进口 NgxEchartsModule在您的应用程序模块(或任何其他适当的 Angular 模块)中:
动态导入

import { NgxEchartsModule } from 'ngx-echarts';

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

您也可以直接传递 echarts,这会减慢初始渲染速度,因为它将整个 echarts 加载到您的主包中。
import { NgxEchartsModule } from 'ngx-echarts';

import * as echarts from 'echarts';

@NgModule({
imports: [
NgxEchartsModule.forRoot({
echarts,
}),
],
})
export class AppModule {}

关于angular - NullInjectorError : No provider for InjectionToken NGX_ECHARTS_CONFIG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63844164/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com