【问题标题】:How to Import other node packages in Angular 4 CLI projects如何在 Angular 4 CLI 项目中导入其他节点包
【发布时间】:2017-12-01 18:11:53
【问题描述】:

我正在尝试在我的 Angular 4/5 CLI 项目中从 npm 导入 graphlib-dot 包。

我将它添加到 angular-cli.json -> 脚本中:[../node_modles/.../graphlib-dot.min.js]

我试图声明 var graphlib: any;在我的 app.component.ts 的顶部。

但 Angular 仍然无法识别这个“graphlib”...

请帮忙...

【问题讨论】:

  • 只需在main.ts文件中导入import * as graphlib from 'graphlib'
  • 尝试这样做 - 声明 var graphlibDot: any;

标签: node.js angular


【解决方案1】:

将 graphlib 添加到 .angular-cli.json

 "scripts": [
    "../node_modules/graphlib-dot/dist/graphlib-dot.min.js"
  ],

然后在组件中

declare var graphlibDot: any;

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})
export class AppComponent {

 constructor() {
    console.log('graphlibDot', graphlibDot);
 }
}

【讨论】:

  • 我对这个领域还很陌生,你能提供一些关于如何为外部 npm js 库找到正确声明名称的提示吗?谢谢
猜你喜欢
  • 2018-04-09
  • 2017-11-13
  • 1970-01-01
  • 2018-03-22
  • 2016-01-15
  • 2019-12-26
  • 2014-07-15
  • 2020-01-04
  • 2018-12-09
相关资源
最近更新 更多