2017-07-26 49 views
0

我有一个基于d3的自定义甘特图书馆。它是用普通的javascript编写的。现在我想将它添加到我的Angular 2应用程序中。我通过媒体链接安装NPM D3并增加了一个类型的文件,以及甘特图到node_modules但我得到了以下错误消息:Angular 2定义文件

__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"; 

node_modules/D3的甘特/ index.js:

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'; 

node_modules/@types/d3-gantt/index.d.ts:

export function gantt(): any; 

的src /应用/ AppComponent.ts

buildGantt(){ 
... 
import * as d3 from 'd3' 
d3.gantt().taskTypes(taskNames).taskStatus(taskStatus).selector('#d3Chart') //here i get the error 
... 
} 
+0

我也有类似的问题,你解决了吗? – David

+0

@David我记得我的解决方案,因为我记得 – Florian

回答

0
  • 在app目录中有
  • 添加Javascript文件夹
  • 地方您的D3-甘特文件夹除了正常的代码添加index.d .ts与行:export function gantt(): any;
  • 在您的app.components.ts中添加import { gantt } from "./javascript/d3-gantt";
  • "allowJs":true,在tsconfig.json

工作就像这对我来说