Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度2定义文件_Javascript_Angular_Typescript_D3.js - Fatal编程技术网

Javascript 角度2定义文件

Javascript 角度2定义文件,javascript,angular,typescript,d3.js,Javascript,Angular,Typescript,D3.js,我有一个自定义甘特图库,它基于d3。它是用普通javascript编写的。现在我想把它添加到我的Angular 2应用程序中。我allready通过npm安装了D3,并将一个类型文件和甘特图添加到节点模块中,但我收到以下错误消息: __WEBPACK_IMPORTED_MODULE_4_d3__.gantt is not a function 我认为这是因为导出和定义文件的错误使用。但我不知道如何解决它 node_modules/d3/index.js: export {version} fr

我有一个自定义甘特图库,它基于d3。它是用普通javascript编写的。现在我想把它添加到我的Angular 2应用程序中。我allready通过npm安装了D3,并将一个类型文件和甘特图添加到节点模块中,但我收到以下错误消息:

__WEBPACK_IMPORTED_MODULE_4_d3__.gantt is not a function
我认为这是因为导出和定义文件的错误使用。但我不知道如何解决它

node_modules/d3/index.js:

export {version} from "./build/package";
export * from "d3-array";
.
.
.
export * from "d3-gantt";
export default gantt;

function gantt()
{
    // a lot of code
    return gantt
}
node_modules/d3 gantt/index.js:

export {version} from "./build/package";
export * from "d3-array";
.
.
.
export * from "d3-gantt";
export default gantt;

function gantt()
{
    // a lot of code
    return gantt
}
node_modules/@types/d3/index.d.ts:

export as namespace d3;
export * from 'd3-array';
.
.
.
export * from 'd3-gantt';
export function gantt(): any;
节点_模块/@types/d3甘特图/index.d.ts:

export as namespace d3;
export * from 'd3-array';
.
.
.
export * from 'd3-gantt';
export function gantt(): any;
src/app/AppComponent.ts

buildGantt(){
...
import * as d3 from 'd3'
d3.gantt().taskTypes(taskNames).taskStatus(taskStatus).selector('#d3Chart') //here i get the error
...
}
  • 在应用程序目录中添加javascript文件夹
  • 将d3甘特图文件夹放在那里
  • 除了常规代码之外,添加index.d.ts,并在下面一行:
    export function gantt():any
  • 在app.components.ts中,从“/javascript/d3-gantt”添加
    import{gantt}
  • 在tsconfig.json中设置
    “allowJs”:true,

像这样为我工作

我也有类似的问题,你解决了吗?@David我按我的记忆发布了我的解决方案