小编lgi*_*lap的帖子

Angular2导入绝对路径或自定义路径(typescript 2)

在我们的angular2项目中,我们将所有模型的ts文件放在特定的文件夹中:/ app/common/model/*.我可以用亲戚路径在我的组件中调用它们,但它非常费力.所以2个解决方案,最好的是自定义路径:StackOverflow:SystemJS和ES模块导入的相对路径.但我的IDE无法找到路径.这是我的tsconfig:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true,
    "outDir": "built",
    "baseUrl": ".",
    "paths": {
      "mymodel/*": [
        "app/common/model/*"
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在我的组件中: import { Address } from 'mymodel/address.model';

IDE:[ts]无法找到模块....我在路径中尝试使用或不使用*

第二种解决方案:Stackoverflow:Angular 2,在不同文件夹之间导入

IDE和编译都可以,组件中有完整路径: import { Address } from 'common/model/address.model';

和tsconfig:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true,
    "outDir": "built", …
Run Code Online (Sandbox Code Playgroud)

path typescript tsconfig angular

7
推荐指数
1
解决办法
2701
查看次数

标签 统计

angular ×1

path ×1

tsconfig ×1

typescript ×1