You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 14集成ng2-charts加载时崩溃问题求助

Angular NG0203 Error with ng2-charts: Injection Context Issue

Hey everyone, I’ve dealt with a similar issue before (though it wasn’t related to ng2-charts), and I’ve spent over a full day digging into this problem. I’m pretty sure this is an environment-level issue, and I really need some technical help here.

Crash Error Message

Error: NG0203: inject() must be called from an injection context (a constructor, a factory function or a field initializer).

Call Stack

at injectInjectorOnly (core.mjs:4751:15)
at Module.ɵɵinject (core.mjs:4762:12)
at Object.NgChartsModule_Factory [as useFactory] (ng2-charts.mjs:274:1)
at Object.factory (core.mjs:9324:38)
at R3Injector.hydrate (core.mjs:9237:35)
at R3Injector.get (core.mjs:9131:33)
at injectInjectorOnly (core.mjs:4757:33)
at ɵɵinject (core.mjs:4761:12)
at useValue (core.mjs:8897:65)
at R3Injector.resolveInjectorInitializers (core.mjs:9174:17)
index.js:551 [webpack-dev-server] Live Reloading enabled.

Code Added in app-module.ts

import { NgChartsModule } from 'ng2-charts';
@NgModule({
  imports: [NgChartsModule,.......]
})

package.json Dependencies

{
  "@angular/animations": "14.1.0",
  "@angular/common": "14.1.0",
  "@angular/compiler": "14.1.0",
  "@angular/core": "14.1.0",
  "@angular/forms": "14.1.0",
  "@angular/material": "14.1.0",
  "@angular/material-moment-adapter": "14.1.0",
  "material-design-icons": "3.0.1",
  "@angular/platform-browser": "14.1.0",
  "@angular/platform-browser-dynamic": "14.1.0",
  "@angular/router": "14.1.0",
  "@types/file-saver": "^2.0.5",
  "core-js": "3.24.0",
  "chart.js": "3.8.2",
  "ng2-charts": "4.0.0",
  "rxjs": "7.5.6",
  "rxjs-compat": "6.6.7",
  "tslib": "2.4.0",
  "zone.js": "0.11.7"
}

Installation Steps

  • npm install --g @angular/cli@14.1.0
  • npm i --unsafe-perm --verbose
  • npm i @types/chart.js

内容的提问来源于stack exchange,提问作者Guy Gallant

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 20:37:32