2017-05-02 55 views
0

采用了棱角分明2.4.0,2.3.1 TSC,我试图用Dagre与JointJS/graphlib使用SystemJS作为装载机Angular2绘制图表。Dagre Angular2 SystemJS模块加载

http://www.daviddurman.com/automatic-graph-layout-with-jointjs-and-dagre.html

我无法弄清楚如何将所要求的JointJS var dagre = require('dagre');

我Angular2组件获得在浏览器中的 'dagre' 对象包括 import * as dagre from 'dagre';

我SystemJS配置:

(function() { 
    System.config({ 
    map: { 
     'dagre': '/static/libs/dagre/dagre.js' 
    } 
}); 
})(); 

不是能够当它试图调用dagre.layout到dagre导致加载到JointJS一个未定义的错误: Cannot read property 'layout' of undefined

// Executes the layout. 
dagre.layout(glGraph, { debugTiming: !!opt.debugTiming }); 

也许这是与库不输出本身还是必须在指定的格式问题我的SystemJS配置?

回答

0

所以我不知道到底是什么固定的,但我做了三件事情:

1)npm install -D @types/dagre

2)在我component.ts

3)添加格式import * as dagre from dagre;:全球到SystemJS配置

(function() { 
    System.config({ 
    map: { 
     'lodash': '/static/libs/lodash/index.js', 
     'dagre': '/static/libs/dagre/dagre.js', 
     'graphlib': '/static/libs/graphlib/grpahlib.umd.js', 
    }, 
    meta: { 
     'dagre': { 
     format: 'global', 
     deps: ['lodash'], 
     }, 
     'graphlib': { 
     format: 'global', 
     deps: ['lodash'], 
     } 
    } 
}); 
})();