2017-05-02 78 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'], 
     } 
    } 
}); 
})();