首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dagre Angular2 SystemJS模块加载

Dagre Angular2 SystemJS模块加载
EN

Stack Overflow用户
提问于 2017-05-02 18:35:52
回答 1查看 347关注 0票数 0

使用角2.4.0,TSC2.3.1,我尝试使用Dagre与JointJS/graphlib一起使用SystemJS作为加载器在SystemJS中绘制图形。

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

我不知道如何按照JointJS var dagre = require('dagre');的要求在浏览器中获取“dagre”对象

我的Angular2组件包括import * as dagre from 'dagre';

我的SystemJS配置:

代码语言:javascript
复制
(function () {
  System.config({
    map: {
        'dagre': '/static/libs/dagre/dagre.js'
    }
});
})();

当JointJS试图调用dagre.layout:Cannot read property 'layout' of undefined时,无法加载dagre会导致未定义的错误

代码语言:javascript
复制
// Executes the layout.
dagre.layout(glGraph, { debugTiming: !!opt.debugTiming });

也许这是库本身没有导出的问题,还是我必须在SystemJS配置中指定一种格式?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-03 22:53:28

所以我不知道到底是什么解决了这个问题,但我做了三件事:

1) npm install -D @types/dagre

2) import * as dagre from dagre; in my component.ts

3)添加的格式:全局到SystemJS配置

代码语言:javascript
复制
(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'],
      }
    }
});
})();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43744940

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档