在Angular 6中导入js外部文件

时间:2018-07-19 13:21:58

标签: javascript d3.js angular6

我正在用角度工作在一个项目中,我不得不将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'

有没有人知道如何以正确的方式做到这一点?谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用社区构建和维护的类型,而不必手工进行输入

相关问题