当尝试将ng2图表添加到新创建的角度项目时,会出现此错误
这似乎是编译时的一个问题
我尝试并搜索了多种方法,但没有成功
错误
这是我的包.json
"private": true,
"dependencies": {
"@angular/animations": "~10.1.0-next.7",
"@angular/common": "~10.1.0-next.7",
"@angular/compiler": "~10.1.0-next.7",
"@angular/core": "~10.1.0-next.7",
"@angular/forms": "~10.1.0-next.7",
"@angular/platform-browser": "~10.1.0-next.7",
"@angular/platform-browser-dynamic": "~10.1.0-next.7",
"@angular/router": "~10.1.0-next.7",
"chart.js": "^2.9.3",
"ng2-charts": "^2.4.1",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1001.0-next.6",
"@angular/cli": "~10.1.0-next.6",
"@angular/compiler-cli": "~10.1.0-next.7",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~3.9.5"
}
这是app.module
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ChartsModule } from 'ng2-charts/lib/charts.module';
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
ChartsModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
尝试更改ChartsModule
的导入,如下所示:
import { ChartsModule } from 'ng2-charts';
请查看StackBlitz,查看使用Angular 10的工作示例。