javascript - 找不到模块 'chart.js'。)Angular 2

标签 javascript angularjs angular charts angular-chart

大家好,我正在使用 Angular2 CLI 并尝试导入 chart.js 模块,但每次我运行服务器时,我都会收到“找不到模块“chart.js”

import { Component } from '@angular/core';
import Chart from 'chart.js';

@Component({
 selector: 'app-root',
 templateUrl: './app.component.html'
 })

 export class AppComponent {
   title = 'Test';
   let myChart = new Chart({});
};

最佳答案

看起来您可能错误地声明了图表导入

你有:

import Chart from 'chart.js';

但应该是:

import { Chart } from 'chart.js';

还要检查你是否安装了 chart.js npm 包,如果你没有正确安装它,你可以安装它:

npm install chart.js --save

关于javascript - 找不到模块 'chart.js'。)Angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43103746/

相关文章:

md-toolbar 的 CSS 媒体查询

javascript - Angular 4奇怪的错误: query doesn't end when -not- showing a message toast

javascript - 匹配正则表达式,处理数字和字母

javascript - 模态窗口的 Controller 可以访问父 Controller 中的函数吗

javascript - 如何使用 AngularJS 合并两个对象?

javascript - Angular Controller /提供程序设置未向前端公开变量

javascript - 如何拦截非 JSON 的响应

javascript - 关联数组中的双索引

javascript - 需要在jsp的 anchor 标记中显示javascript值

javascript - 在弹出窗口以外的任何地方单击时关闭弹出窗口?