因此,我正在尝试为项目设置NG2-charts,但是一旦我在app.module.ts import
中导入模块,它就会给我以下错误消息:
Uncaught TypeError: Object(...) is not a function
at ng2-charts.js:230
at Object.<anonymous> (ng2-charts.js:232)
at __webpack_require__ (bootstrap 1f12d1e1e27208e77f22:54)
at Object.286 (main.ts:5)
at __webpack_require__ (bootstrap 1f12d1e1e27208e77f22:54)
at Object.264 (main.ts:1)
at __webpack_require__ (bootstrap 1f12d1e1e27208e77f22:54)
at webpackJsonpCallback (bootstrap 1f12d1e1e27208e77f22:25)
at main.js:
,如果我们在ng2 -charts.js文件中检查该行 -
/** @nocollapse */ ThemeService.ngInjectableDef = defineInjectable({ factory: function ThemeService_Factory() { return new ThemeService(); }, token: ThemeService, providedIn: "root" });
我已经安装了Chart.js并将其导入App.component.ts文件如下 -
import '../../node_modules/chart.js/dist/Chart.bundle.min.js';
import '../../node_modules/chart.js/dist/Chart.min.js';
这就是app.module.ts文件导入部分看起来像 -
/**
* Import Angular and Ionic libraries.
*/
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
/**
* Import third-party libraries.
*/
import { ChartsModule } from 'ng2-charts';
@NgModule({
declarations: [
...
],
imports: [
BrowserModule,
IonicModule.forRoot(EnlightMobileApp),
IonicStorageModule.forRoot(),
ChartsModule
],
bootstrap: [IonicApp],
entryComponents: [
...
],
providers: [
...
]
})
export class AppModule {}
ng2-charts-x解决了NG2-Charts的一些未解决的问题,您应该尝试一下。只需按照读数安装它,它与您所做的类似,但不直接导入app.component.ts。
它对我有用!
npm install --save ng2-charts@~2.2.5