简体   繁体   English

在角度4应用程序中设置路径别名

[英]Set path alias in angular 4 application

Is there any way to set path aliases in Angular with TypeScript since putting path like 有没有办法用TypeScript在Angular中设置路径别名,因为放置路径就好了

import { AuthService } from '../../../common/AuthService';
import { ContactService } from '../../../common/ContactService';

It is very confusing ie to remember the relative path URI. 记住相对路径URI是非常混乱的。 Is there any way to create path aliases and use them throughout the application, like browserify ? 有没有办法创建路径别名并在整个应用程序中使用它们,比如browserify

If you use typescript, the best way to deal with this problem is to put paths configuration in project's tsconfig.json: 如果使用typescript,处理此问题的最佳方法是将路径配置放在项目的tsconfig.json中:

"baseUrl": "src",
"paths": {
  "@app/*": ["app/*"],
  "@env/*": ["environments/*"]
}

Please, refer 2nd point in the following article https://medium.com/@tomastrajan/6-best-practices-pro-tips-for-angular-cli-better-developer-experience-7b328bc9db81 , or official ts docs https://www.typescriptlang.org/docs/handbook/module-resolution.html#base-url 请参阅以下文章https://medium.com/@tomastrajan/6-best-practices-pro-tips-for-angular-cli-better-developer-experience-7b328bc9db81或官方ts docs https中的第二点: //www.typescriptlang.org/docs/handbook/module-resolution.html#base-url

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM