【问题标题】:Import d3js into Ionic2 typescript project将 d3js 导入 Ionic2 typescript 项目
【发布时间】:2016-10-30 12:46:53
【问题描述】:

我无法理解如何在 ionic typescript projet 中导入 d3js 库。我使用以下方法安装了库:

npm install d3 --save-dev

该库位于 node_modules/d3 中。在我的页面模块中,我尝试使用所有可能的路径进行导入,例如:

import * as d3 from 'd3/d3'
import * as d3 from '../../../node_modules/d3/d3'

我总是得到错误:

Error TS2307: Cannot find module 'd3/d3'.
or 
Error TS2307: Cannot find module '../../../node_modules/d3/d3'`.

有什么提示可以帮助我吗?

Angular 版本 2.0.0-rc.1

离子:2.0.0-beta.9

谢谢

【问题讨论】:

标签: d3.js angular ionic2


【解决方案1】:

我使用了解决方法。

我做了什么:

在 index.html 中链接 d3js(在文件末尾,位于 app.bundle.js 下方):

<script src="https://d3js.org/d3.v3.min.js"></script>

然后在我的 page.ts 中(@Component 之前):

declare var d3: any;

然后你可以像这样使用它:

d3.select("#graph svg").remove();

所以我没有使用导入(如果你想使用这个解决方案,你应该删除导入)

【讨论】:

    【解决方案2】:

    试试这个:

    npm install @types/d3 --save
    

    我刚试了一下,效果很好。更多信息here

    【讨论】:

      猜你喜欢
      • 2017-07-01
      • 1970-01-01
      • 2020-06-15
      • 2017-01-23
      • 2017-08-08
      • 1970-01-01
      • 1970-01-01
      • 2016-12-01
      • 1970-01-01
      相关资源
      最近更新 更多