angular - ng2-Chart 不适用于新创建的 Angular 10 项目
问题描述
尝试将 ng2-charts 添加到新创建的角度项目时,会出现此错误
编译时似乎是个问题
我尝试并搜索了多种方法,但没有运气
这是我的 package.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 的工作示例。
推荐阅读
- c# - .Net 事件网格 Webhook 模型绑定错误
- sonarcloud - 意外符号:'2e4ce68d4e3feec97e992821e6391166943f4d49'
- python - Python - 乘法表创建
- git-bash - 如何在同一目录的 Windows 终端中打开一个新的 git-bash 选项卡?
- spring - 实施项目以在本地启动 spring 云数据流服务器时出错
- javascript - 获取使用 WebdriverIO v5 显示的元素数量
- kubernetes - 是否有已知的方法来确定自动缩放阈值?
- javascript - 如何修复“TypeError:未定义不是对象”?
- google-cloud-platform - 使用 Deployment Manager 配置防火墙和启动脚本
- spring-boot - 我应该如何定义要使用的 Hibernate 映射,以及何时/何地使用它?