【问题标题】:import js external file in angular 6以角度6导入js外部文件
【发布时间】:2018-07-19 13:21:57
【问题描述】:

我在一个 Angular 项目中工作,我必须在其中集成 D3JS,我使用了

npm install d3

并且工作正常。 我需要在 js 文件中使用一个函数。我按照一些步骤导入它,但仍然出现错误,这是我所做的: 我把js文件放在node模块中。 然后我在 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 中开发的函数 labeler:

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 d3.js angular6


    【解决方案1】:

    您可以使用社区构建和维护的类型,而不是手工制作类型

    【讨论】:

    • 该文件,我想添加的文件在 D3 实验室中不存在,这就是我正在尝试这样做的方式,并且已经使用了 npm install d3 --save,但是我正在尝试要做的就是在外部文件中导入一个函数
    猜你喜欢
    • 2017-10-18
    • 2017-02-15
    • 1970-01-01
    • 2023-03-08
    • 2021-10-16
    • 1970-01-01
    • 2016-09-02
    • 2016-10-24
    • 2015-01-11
    相关资源
    最近更新 更多