【问题标题】:Cannot find module 'chart.js'.) Angular 2找不到模块'chart.js'。)Angular 2
【发布时间】:2017-03-29 20:42:01
【问题描述】:

大家好,我正在使用 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.js/dist/Chart.min.js';假设你已经对 chartjs 进行了 npm 安装。
  • 我做了 npm 安装但没有修复它。我需要从它的目录导入图表

标签: javascript angularjs angular charts angular-chart


【解决方案1】:

您似乎错误地声明了您的图表导入

你有:

import Chart from 'chart.js';

但应该是:

import { Chart } from 'chart.js';

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

npm install chart.js --save

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    相关资源
    最近更新 更多