如何在用Angular CLI构建的应用程序中使用JointJS?

维奈·普拉巴卡兰(Vinay Prabhakaran)

我已经通过npm安装了jointjs,并且还安装了类型输入和代码编译/构建。

import { Component } from '@angular/core';
import  * as joint from '../../node_modules/jointjs/dist/joint.min';


export class AppComponent {
  title = 'app works!';
  constructor(
  ) {
    // console.log(joint)// private jint: joint,
  }

  ngOnInit() {
    var graph = new joint.dia.Graph;
  }
}

错误显示在浏览器上:

Failed to compile.

/home/vinay/angularapps/jjs/src/app/app.component.ts (17,31): Property 'Graph' does not exist on type '{}'.)

我的cli.json文件..添加了jointjs的脚本和样式

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "version": "1.0.0-beta.32.3",
    "name": "jjs"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "styles": [
        "styles.css",
        "../node_modules/jointjs/css/layout.css"
      ],
      "scripts": ["../node_modules/jointjs/dist/joint.js"],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "files": "src/**/*.ts",
      "project": "src/tsconfig.json"
    },
    {
      "files": "e2e/**/*.ts",
      "project": "e2e/tsconfig.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}

我在其中添加allowJs的tsconfig.json文件

{
  "compilerOptions": {
    "baseUrl": "",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2016",
      "dom"
    ],
    "mapRoot": "./",
    "module": "es2015",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "allowJs": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  }
}

我无法弄清楚如何创建此链接http://resources.jointjs.com/tutorial/hello-world上提供的简单hello world应用程序

维奈·普拉巴卡兰(Vinay Prabhakaran)

好的,我终于得到了与@angular cli一起工作的jointjs,以下是步骤

角度项目目录中的命令提示符下

  1. 您的新应用
  2. 进入您的应用
  3. npm install jquery --save npm install @ types / jquery --save-dev
  4. npm install主干--save npm install @ types / backbone --save-dev
  5. npm install jointjs-保存npm install @ types / jointjs --save-dev
  6. npm install [email protected]保存npm install @ types / lodash @ 3.10.1 --save-dev

确保在package.json中,条目显示在主干,jquery,jointjs,lodash的依赖项和devDepencies下,并确保它们是版本

jointjs 1.0.3,backbome = 1.3.3,jquery = 3.1.1,lodash = 3.10.1

angular-cli.json文件中

在styles属性和脚本中; []属性添加如下的联合js详细信息

  "styles": [
    "styles.css",
    "../node_modules/jointjs/css/layout.css"
  ],
  "scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/jointjs/dist/joint.js"
  ],

您的component.html中

 <div id="paper"></div>

你的component.ts中

import * as jQuery from 'jquery';
import * as _ from 'lodash';
import * as $ from 'backbone';
const joint = require('../../../../node_modules/jointjs/dist/joint.js');

ngOnInit() {
    let graph = new joint.dia.Graph;

    let paper = new joint.dia.Paper({
      el: jQuery("#paper"),
      width: 600,
      height: 200,
      model: graph,
      gridSize: 1
    });

    let rect = new joint.shapes.basic.Rect({
      position: { x: 100, y: 30 },
      size: { width: 100, height: 30 },
      attrs: { rect: { fill: 'blue' }, text: { text: 'my box', fill: 'white' } }
    });

    let rect2 = rect.clone() as joint.shapes.basic.Rect;
    rect2.translate(300);

    var link = new joint.dia.Link({
      source: { id: rect.id },
      target: { id: rect2.id }
    });

    graph.addCells([rect, rect2, link]);
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用angular-cli构建多个应用程序?

如何使用本机cli构建本机应用程序?

如何在angular 5应用程序中使用CLI创建新的@ngrx文件?

如何构建Node CLI应用程序

如何在PHP应用程序中使用Angular 2?

如何在webpack中使用angular-cli在angular2应用程序中导入xml2js

如何在JavaFX应用程序中使用Spring Boot构建插件

如何在 Linux 中使用 Maven 构建 Flink 应用程序

如何在 docker 中使用 cargo 构建和运行我的 Actix 应用程序?

如何在 Angular 7 应用程序中使用 GWT 应用程序作为组件?

使用 Angular CLI 在 Angular 2 中部署新的应用程序构建后通知用户

使用Nginx投放Angular2 CLI构建的应用程序会抛出404、403

使用node和@ angular / cli构建的应用程序可以脱机运行吗?

自动构建 angular cli 应用程序缓存文件问题

在Angular 5中使用电子生成器构建电子应用程序

如何使用angular-cli将构建时环境变量添加到应用程序中?

在带有 NPM 的 Angular 4 应用程序中使用分叉的 Angular-CLI

在angular cli应用程序中使用vtk.js / glsl文件

如何在带有角度cli的angular2应用程序中使用gulp浏览器浏览器同步?

如何在Java应用程序中使用Akka Actors?

如何在 PopSQL 应用程序中使用 DELIMITER 语句?

如何在多线程应用程序中使用Hibernate?

如何在Qt应用程序中使用Windows字体

电子-如何在电子应用程序中使用ffmpeg

如何在聊天应用程序中使用Dhtmlx消息

如何在NestJS应用程序中使用矩

如何在 html iframe 中使用 heroku 应用程序?

如何在可可应用程序中使用UKKQueue?

如何在我的应用程序中使用ORKESerializer?