我正在尝试在Ionic 3项目中使用chart.js,但是当我在“ app.module.ts”中导入ChartsModule时,它会生成错误。我收到此错误
对象(__WEBPACK_IMPORTED_MODULE_2_aangular_core))[«defineInjectable»])不是函数…
...
import { ChartsModule } from 'ng2-charts';
@NgModule({
declarations: [ MyApp ],
imports: [
BrowserModule,
FormsModule,
IonicModule.forRoot(MyApp),
AngularFireModule.initializeApp(FIREBASE_CONFIG),
AngularFireAuthModule,
AngularFireDatabaseModule,
ChartsModule
],
...
这是我的“ package.json”文件代码,如下所示: 这是下面的“ package.json”文件代码: 这是我下面的“ package.json”文件代码:
{
"name": "Beep",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "5.0.3",
"@angular/compiler": "5.0.3",
"@angular/compiler-cli": "^7.2.13",
"@angular/core": "5.0.3",
"@angular/forms": "5.0.3",
"@angular/http": "5.0.3",
"@angular/platform-browser": "5.0.3",
"@angular/platform-browser-dynamic": "5.0.3",
"@ionic-native/core": "4.4.0",
"@ionic-native/splash-screen": "4.4.0",
"@ionic-native/status-bar": "4.4.0",
"@ionic/storage": "2.1.3",
"angularfire2": "^5.0.0-rc.5-next",
"chart.js": "^2.8.0",
"cordova-android": "7.1.4",
"cordova-ios": "4.5.5",
"cordova-plugin-device": "^1.1.7",
"cordova-plugin-ionic-keyboard": "^2.1.3",
"cordova-plugin-ionic-webview": "^4.0.1",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-whitelist": "^1.3.3",
"firebase": "^4.9.1",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"ng2-charts": "^2.2.2",
"rxjs": "5.5.2",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.18"
},
"devDependencies": {
"@ionic/app-scripts": "^3.2.3",
"@ionic/lab": "1.0.18",
"typescript": "2.4.2"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-whitelist": {},
"cordova-plugin-device": {},
"cordova-plugin-ionic-webview": {},
"cordova-plugin-ionic-keyboard": {},
"cordova-plugin-splashscreen": {}
},
"platforms": [
"ios",
"android"
]
}
}
答案 0 :(得分:0)
对于Angular 7或更高版本,请使用
npm安装ng2-charts@2.2.3-保存
npm install chart.js-保存