【问题标题】:In angular 4: ReferenceError: d3 is not defined while on importing in module在角度 4 中:ReferenceError:在模块中导入时未定义 d3
【发布时间】:2017-12-28 11:02:06
【问题描述】:

我想在我的 app.module 中以角度 4 导入它。而不是将它插入到我的索引文件中。

In app.module.ts -> 

import d3 from "d3";
console.log(d3) // shows that D3 is successfully imported

import nvd3 from "nvd3";

页面抛出以下错误:

ReferenceError: d3 未定义

另外,我在 package.json 中添加了这些依赖项

【问题讨论】:

  • @AmruthLS,不,它不是重复的
  • 为什么是重复的? @AmruthLS 吗?请解释一下。
  • 试试import * as d3 from d3
  • @HuguesStefanskiI 我试过了。它不工作。仍然出现同样的错误。
  • 我建议你使用 ngx-charts 比 nvd3 更好

标签: javascript angular d3.js nvd3.js


【解决方案1】:

只需在你的模块中使用,

import 'd3';
import 'nvd3';

只需在顶部的组件中声明 d3

declare var d3: any;

【讨论】:

  • 在顶部的组件中声明 d3:- 声明 var d3: any;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多