将 d3js 导入 Ionic2 打字稿项目
Import d3js into Ionic2 typescript project
我无法理解如何在 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
谢谢
我使用了这个问题的解决方法。
我做了什么:
Link 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();
所以我没有使用导入(如果你想使用这个解决方案,你应该删除导入)
试试这个:
npm install @types/d3 --save
我刚刚试过了,很管用。更多信息 here.
我无法理解如何在 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
谢谢
我使用了这个问题的解决方法。
我做了什么:
Link 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();
所以我没有使用导入(如果你想使用这个解决方案,你应该删除导入)
试试这个:
npm install @types/d3 --save
我刚刚试过了,很管用。更多信息 here.