【问题标题】:Using jointjs in angular2/typescript在angular2/typescript中使用jointjs
【发布时间】:2023-04-03 03:50:01
【问题描述】:

我和我的朋友想在angular2/typescript 中使用jointjs,它是用JavaScript 编写的。我们尝试了各种关于如何在 typescript 中导入 javascript 库的教程,但对我们/jointjs 没有任何帮助。导入jointjs时有什么特别需要考虑的吗?

问候

【问题讨论】:

  • 你有什么特别的错误信息吗?请描述您尝试了什么以及结果。
  • 我们总是收到错误“找不到模块 xxx”。我们只是尝试了各种不同的方式来导入库(我们无法真正记住我们尝试过的所有内容)。是否可以在没有库的类型定义文件的情况下在 typescript 中导入 javascript 库?

标签: javascript typescript angular jointjs


【解决方案1】:

你安装了jointjs的类型吗?

typings install jointjs --save

这应该可以消除错误消息。

要在打字稿类中导入库,这应该可以:

import * as jointjs from 'jointjs';

【讨论】:

    【解决方案2】:

    你试过这个吗:

    import * as joint from 'joint';
    
    export class JointAwareClass {
      joint:any = joint;
      constructor() {}
    }
    

    现在在创建主组件时,扩展它:

    export class AppComponent extends JointAwareClass  {
      constructor() {}
    }
    

    【讨论】:

    • 感谢您的快速回复。可悲的是它也不起作用。当我们尝试导入关节(import * as joint from 'joint';)时,就像您提到的那样,我们收到消息:“找不到模块 'joint'”。我们还尝试了这个 '../../../node_modules/jointjs/index.js' 和这个 '../../../node_modules/jointjs/dist/joint.js' 而不是 'joint'结果相同。我们在第一个路径中引用的 index.js 仅包含“module.exports = require()'./dist/joint';”如果这有任何帮助。
    • @AngJobs 请你提供一个更具描述性的例子
    猜你喜欢
    • 1970-01-01
    • 2016-06-12
    • 2016-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    • 2016-11-29
    • 2017-01-15
    相关资源
    最近更新 更多