我正在使用Angular 4,并且希望将mxGraph集成到我的项目中。
我已经用谷歌搜索了,但是我没有得到完整的工作示例。
我尝试了以下方式,但它也对我不起作用。
我遵循的步骤:
npm install mxgraph --save
用于mxgraph的npm软件包:https://www.npmjs.com/package/mxgraph
npm install lgleim/mxgraph-typings --save
Github Repo的mxgraph-类型-https://github.com/lgleim/mxgraph-typings
import {mxgraph} from 'mxgraph';
{"glob":"**/*", "input":"node_modules/mxgraph/javascript/src", "output": "./mxgraph"}
const graph: mxgraph.mxGraph = new mxgraph.mxGraph(document.getElementById('graphContainer'));
当我运行
ng serve
然后我遇到问题/错误:
Module not found: Error: Can't resolve 'mxgraph' in 'path to my file where I have imported and used mxgraph'
const mx = require('mxgraph')({
mxImageBasePath: 'mxgraph/images',
mxBasePath: 'mxgraph'
});
像这样使用:
const graph: mxgraph.mxGraph = mx.mxGraph(document.getElementById('graphContainer'));
当我运行
ng serve
这次我也遇到同样的问题/错误:
Module not found: Error: Can't resolve 'mxgraph' in 'path to my file where I have imported and used mxgraph'
有谁知道我在这里想念的东西吗?或为什么它不起作用?
如果有人知道将mxGraph与Angular 4集成的任何其他/更好的方式,请告诉我。
提前致谢 !!
最佳答案
如果有人还在为Angular 4/5/6中的mxGraph集成而苦苦挣扎。然后是完整的解决方案:
有关不同的mxGraph存储库的一些详细信息:
Repo-1: https://github.com/jgraph/mxgraph
This is an official release repo of mxGraph. With npm issues.
Repo-2: https://bitbucket.org/jgraph/mxgraph2
This is an official development repo of mxGraph. With npm issues.
If anyone wants to see what npm issues with these above repos(i.e. Repo-1 and Repo-2), then check these following issues:
- https://github.com/jgraph/mxgraph/issues/169
- https://github.com/jgraph/mxgraph/issues/175
Repo-3: https://bitbucket.org/lgleim/mxgraph2
Fork of Repo-2. With npm fixes.
Repo-4: https://github.com/ViksYelapale/mxgraph2
Fork of Repo-2. Merged npm fixes from Repo-3 as well. Added changes(i.e. required for local installation of mxGraph) to this repo.
步骤:
$ cd mxgraph2
$ npm install
$ npm install /path/to/mxgraph2
例如
npm install /home/user/workspace/mxgraph2
它将在package.json文件中添加如下所示的类似条目:
"mxgraph": "file:../mxgraph2"
$ npm install
注意- typescript 的最低要求版本是2.4.0
$ npm install lgleim/mxgraph-typings --save
一世。 component.ts
import { mxgraph } from "mxgraph";
declare var require: any;
const mx = require('mxgraph')({
mxImageBasePath: 'assets/mxgraph/images',
mxBasePath: 'assets/mxgraph'
});
.
.
.
ngOnInit() {
// Note - All mxGraph methods accessible using mx.xyz
// Eg. mx.mxGraph, mx.mxClient, mx.mxKeyHandler, mx.mxUtils and so on.
// Create graph
var container = document.getElementById('graphContainer');
var graph = new mx.mxGraph(container);
// You can try demo code given in official doc with above changes.
}
ii。 component.html
<div id="graphContainer"></div>
希望对您有所帮助。