在Angular 6中导入外部js文件

3

我正在一个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'

有没有人知道如何以正确的方式进行IT技术方面的工作?谢谢。
1个回答

0

我想要添加的文件在D3库中不存在,这就是为什么我正在尝试使用这种方法来完成它,并且已经使用了npm install d3 --save,但我正在尝试做的是从外部文件导入一个函数。 - B. Bob

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接