javascript - 导入一个没有 Angular 6 路径的模块

标签 javascript angular typescript

我有一个名为 ng2-toastr 的第三方模块,我将其移至我的应用程序文件夹之一,并将其​​从节点模块中删除,并使用 npm uninstall ng2-toastr。现在我想通过它的名称将它导入到我的 AppModule 和其他模块中(就像我以前在 node_modules 中所做的那样)而不是通过它的路径,我该怎么做?

最佳答案

您可能想详细阅读本文http://www.typescriptlang.org/docs/handbook/module-resolution.html

话虽如此,您可以通过添加 tsconfig.json 的路径来实现该文档中所述的目的。

{
  "compilerOptions": {
    "baseUrl": ".", // This must be specified if "paths" is.
    "paths": {
      "yourmodule": ["path/to/yourmodule"] // This mapping is relative to "baseUrl"
    }
  }
}

请注意,node_modules 内部的内容有一个默认的树遍历方法来执行您想要的操作,这就是为什么当您在 node_modules 中使用该方法时它会起作用(该文档中也有详细说明)。

关于javascript - 导入一个没有 Angular 6 路径的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52699821/

相关文章:

javascript - 使用 javascript 模拟表单 POST 到 ASP.NET MVC

javascript - highcharts 中的数千个运算符

javascript - 当我更改 View 时,Angular2 不加载外部 js 文件

angular - Jasmin + karma : "Error: Unexpected value ' HttpClient' imported by the module 'DynamicTestModule' . 请添加@NgModule 注解。”

angular - 如何在 RxJS 主题中修改 map ?

javascript - 使用 PHP 抓取 SQL 数据,然后将数组发送到 Javascript

javascript - 如何创建热键

使用 Angular-CLI 进行 Angular 2 设置

Angular 5.x 页面加载或模块本身的初始化需要更长的时间

angular - Jasmine : How to SpyOn a method callback : method. then()