【问题标题】:angular: custom imports - specifying path to file角度:自定义导入 - 指定文件路径
【发布时间】:2019-08-22 00:41:45
【问题描述】:

还有其他方法 - 一种更简洁的方法来指定我的导入路径吗?我指的是点和正斜杠

我有这样的事情:

import { Product } from '../../../../../../@core/model/v2/domain/product';
import { ConfigService } from '../../../../../../@core/data/config.service';
import { ProductMappingContainer } from '../../../../../../@core/model/v2/dto/productMappingContainer';
import { AddProductModalSource } from '../../../../../../@core/model/v2/types/addProductModalSource';

【问题讨论】:

标签: angular import


【解决方案1】:

打字稿编译器允许路径映射。

在您的 tsconfig.json 文件中,您可以添加 baseurl:

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

然后在您的导入中:

import { MyComponent } from '@shared/components/mycomponent'

这取自medium-itnext article

【讨论】:

    猜你喜欢
    • 2018-09-02
    • 2017-04-22
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2017-06-16
    相关资源
    最近更新 更多