【问题标题】:Is there any option to namespace a module folder path in angular 2-5?是否有任何选项可以命名 Angular 2-5 中的模块文件夹路径?
【发布时间】:2018-07-27 03:12:22
【问题描述】:

有没有办法在 Angular 5 中为自定义路径使用命名空间? 目前我使用

import { AuthService } from './../../modules/auth/auth.service';

我想要实现的是对特定路径使用@module 或自定义@name。代码应如下所示,并且可以在每个文件夹级别使用

import { AuthService } from '@modules/auth/auth.service';

【问题讨论】:

标签: angular typescript angular5


【解决方案1】:

是的,tsconfig.json 配置中有paths 属性:

{
   ...
   "compilerOptions": {
       ...
       "paths": {
           "@core/*": ["app/core/*"],
           "@shared/*": ["app/shared/*"]
    }      
}

【讨论】:

  • 这成功了,一切正常,但我的 Vs-code IDE 在线显示错误。知道任何解决方法吗?
  • 不确定,我的 IDE 读取这些路径并且知道如何处理它。有一个错误打开:github.com/angular/angular-cli/issues/8138 也许再搜索一下,看看其他人是否有这个问题?
  • 修复它..我使用'@module'来导入所有导出的成员,而不是我使用'@module/index'
猜你喜欢
  • 2019-08-26
  • 1970-01-01
  • 2015-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-13
相关资源
最近更新 更多