我在一个 Angular 项目中工作,我必须在其中集成 D3JS,我使用了
npm install d3
并且工作正常。 我需要在 js 文件中使用一个函数。我按照一些步骤导入它,但仍然出现错误,这是我所做的: 我把js文件放在节点模块中。 然后我在 angular.json 文件中添加了这样的路径:
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/materialize-css/dist/js/materialize.min.js",
"node_modules/d3/labeler.js"
]
在导入中我使用了这个脚本:
import * as labeler from 'labeler.js';
然后我添加这个声明:
declare var labeler: any;
最后我想以这种方式使用我在 labeler.js 中开发的函数标签器:
d3.labeler()
我得到了这个错误:
[WDS] Warnings while compiling. client:147
./node_modules/labeler.js
4:16-26 "export 'labeler' (imported as 'd3') was not found in 'd3' client:153
./src/app/components/init-map-markers/init-map-markers.component.ts
916:8-18 "export 'labeler' (imported as 'd3') was not found in 'd3'
有没有人知道如何以正确的方式做到这一点?谢谢
最佳答案
您可以使用社区构建和维护的类型,而不是手动制作类型
关于javascript - 以 Angular 6导入js外部文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51423800/