cytoscape.js 和 Angular6 [英] cytoscape.js and Angular6
问题描述
我想在我的 angular 项目中导入 cytoscape.js 库,但我不知道如何去做吧.据我所知,angular 没有官方的 cytoscape 模块,有什么办法可以手动导入 cytoscape 吗?
I want to import cytoscape.js library in my angular project, but I don't know how to do it. As far as I know, there is no official cytoscape module for angular, is there any way to import cytoscape manually?
推荐答案
UPDATE:请看 D.C. Joo 的回答,这应该是公认的答案.
UPDATE: Please see the answer of D.C. Joo, this should be the accepted answer.
其实在Angular中导入JS库是没有问题的,这就是我使用npm和Angular6的方式:
Actually, it's no problem to import JS libraries in Angular, thats how I do it using npm and Angular6:
- 运行
npm install cytoscape
- 从
https://github.com/cytoscape/cytoscape.js/blob/master/dist/cytoscape.min.js
下载Cytoscape - 在你的 Angular 根目录中创建一个目录
scripts
并将下载的文件放在那里 将您下载的脚本包含在您的
angular.json
中:
- Run
npm install cytoscape
- Download Cytoscape from
https://github.com/cytoscape/cytoscape.js/blob/master/dist/cytoscape.min.js
- Create a directory
scripts
in your Angular root directory and place the downloaded file there Include your downloaded script in your
angular.json
:
项目":{我的项目": {...建筑师":{建造": {...脚本":[src/scripts/cytoscape.min.js"]...(注意:抱歉格式化,我试过了,但它不想工作)
"projects": { "myproject": { ... "architect": { "build": { ... "scripts": [ "src/scripts/cytoscape.min.js" ] ... (NOTE: Sorry about the formatting, I tried but it does not want to work)
在要使用 Cytoscape 的 Angular 组件中,将 declare var cytoscape: any;
添加到导入
In the Angular component where you want to use Cytoscape, add declare var cytoscape: any;
to the imports
现在您可以像往常一样使用 Cytoscape,玩得开心:)
Now you can use Cytoscape like you would normally, have fun :)
这篇关于cytoscape.js 和 Angular6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!